开发者

Drawing a gripper in a borderless form

So I've got a borderless form and I need it to be re-sizable (by clicking any of the 4 sides or the corners). To clarify, I want my form to be borderless like the default sticky notes in Windows 7.

Drawing a gripper in a borderless form

I've got it to work (on bottom right corner only for now) by using the code provided by Julien Lebosquain on this post:

Resize borderless window on bottom right corner

However, I would really like to display the drag gripper image on the bottom right corner. In his post, Julien mentioned this regarding the gripper:

you can initialize a new

VisualStyleRenderer(VisualStyleElement.Status.Gripper.Normal) and

use its PaintBackground() method.

I'm not sure how to go about doing this within 开发者_JS百科my form. Can someone point me in the right direction?

Thank you.


So after reading up on it a bit here: http://msdn.microsoft.com/en-us/library/system.windows.forms.visualstyles.visualstyleelement.status.gripper.normal.aspx, I've got the solution.

First override the OnPaint() event for the form.

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

And the method that does the drawing.

   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);
       }
   }


See this post at CodeProject http://www.codeproject.com/KB/cs/borderlessform.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜