Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

enter image description here

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 my form. Can someone point me in the right direction?

Thank you.

like image 664
Vaheh Avatar asked Feb 07 '11 01:02

Vaheh


2 Answers

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);
       }
   }
like image 143
Vaheh Avatar answered Sep 16 '22 13:09

Vaheh


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

like image 28
Javed Akram Avatar answered Sep 18 '22 13:09

Javed Akram