Page 1 of 1

Making a Size Grip for a borderless form Rate Topic: -----

#1 The Prodigy  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 03-October 11

Posted 14 October 2011 - 11:45 AM

Borderless forms give you the opportunity to create a more personalized and beautiful application interface, but it does come with a few set-back, one being that there's no size grip to replace the border. This, of course, isn't always a problem, such as when you don't want the window resized. But for when it is a problem, I've come up with a simple solution.

Step 1
You will first need to create or download an image to represent the size grip. The best designs are either:
Three parallel lines pointing north-east, the second line being smaller than the first, and the third being smaller than the second.
Or
Small dots forming a right triangle with a north-west facing hypotenuse. Here's an example with periods:
.
..
...

Because I'm just sooooo nice ( :dozingoff: ), I've attached a grip PNG image I made in the crazy case you wouldn't want to make your own.
Attached Image

Step 2
Open your project with the borderless form, and add a picturebox control to the bottom-right corner of the form. Rename the control "Grip" and change its image property to your size grip image (either the one you made or the own you downloaded above). (You will also need to change the anchor property to Bottom, Right.)
Now going to code view, we're going to have to set up two Integer variables and one Boolean variable. Enter the following code at the top of the class:
Dim GripDrag As Boolean
Dim InitialSizeX As Integer
Dim InitialSizeY As Integer


Step 3
Add the Grip_MouseDown event code (again - Grip is your picture box control), and then type the following code into that event:
If e.Button = Windows.Forms.MouseButtons.Left Then 'If the control is being left-clicked
    GripDrag = True 'Confirms the grip is ready to be dragged
    InitialSizeX = Me.Width 'Sets the initial width
    InitialSizeY = Me.Height 'Sets the initial height
End If


Step 4
Add the Grip_MouseMove event code, and then type the following code into that event:
If GripDrag = True Then
    Me.Width = InitialSizeX + (Windows.Forms.Cursor.Position.X - (Me.Width + Me.Location.X)) 'Increases the width of the form by the amount the grip has been dragged towards the right
    Me.Height = InitialSizeY + (Windows.Forms.Cursor.Position.Y - (Me.Height + Me.Location.Y)) 'Increases the height of the form by the amount the grip has been dragged downward

    InitialSizeX = Me.Width 'Resets the value to the form's current width
    InitialSizeY = Me.Height 'Resets the value to the form's current height

    Me.Refresh()
End If


Step 5
Add the Grip_MouseUp event code, and then type the following code into that event:
GripDrag = False 'Confirms the grip is no longer being dragged


And that's all there is to making your own Size Grip! I hope that you have found this tutorial helpful and will give it a good rating :bigsmile:

If there is an area you see that this tutorial could improve in, please let me know by messaging me. Hope you enjoyed my first tutorial :w00t:

This post has been edited by The Prodigy: 21 October 2011 - 10:25 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Making a Size Grip for a borderless form

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9197
  • View blog
  • Posts: 34,550
  • Joined: 12-June 08

Posted 20 October 2011 - 06:19 PM

The only thing I suggest is setting the anchor points to the bottom and right of the form if you are putting it in the bottom-right corner. If you leave the default then the 'grip' picture box control doesn't move with the form!
Was This Post Helpful? 0
  • +
  • -

#3 The Prodigy  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 03-October 11

Posted 21 October 2011 - 10:24 AM

Ah yes I forgot to add that part. Thanks for the reminder.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1