2011-02-07 98 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); 
     } 
    }