2011-02-07 95 views
5

所以我有一個無邊界形式,我需要它可以重新設置大小(通過點擊任何四邊或角落)。爲了澄清,我希望我的形式是無國界的,如默認即時貼在Windows 7繪製無邊界形式的抓手

enter image description here

我知道了利用所提供的代碼工作(在右下角現在只)朱利安Lebosquain對這個職位:

Resize borderless window on bottom right corner

不過,我真的想在右下角顯示拖動夾具圖像。在他的崗位,朱利安提到這對於夾具:

可以初始化一個新
VisualStyleRenderer(VisualStyleElement.Status.Gripper.Normal)和
使用其PaintBackground()方法。

我不確定如何在我的表單中執行此操作。有人能指引我朝着正確的方向嗎?

謝謝。

+0

你想要什麼,它是由4個角落和4個側面拖拽還是僅從4個角落拖動? – 2011-02-07 02:39:15

+0

4角和4邊。但是,我的當務之急是讓抓取者圖像顯示在右下角,以顯示我的表單可以重新分級。 – Vaheh 2011-02-07 02:45:36

回答

7

所以在這裏就可以讀了一下後:http://msdn.microsoft.com/en-us/library/system.windows.forms.visualstyles.visualstyleelement.status.gripper.normal.aspx,我已經得到了解決。

首先覆蓋表單的OnPaint()事件。

protected override void OnPaint(PaintEventArgs e) { 
     base.OnPaint(e); 
     DrawGripper(e); 
    } 

和做繪圖的方法。

public void DrawGripper(PaintEventArgs e) { 
     if (VisualStyleRenderer.IsElementDefined(
      VisualStyleElement.Status.Gripper.Normal)) { 
      VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Status.Gripper.Normal); 
      Rectangle rectangle1 = new Rectangle((Width) - 18, (Height) - 20, 20, 20); 
      renderer.DrawBackground(e.Graphics, rectangle1); 
     } 
    }