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 (

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
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
This post has been edited by The Prodigy: 21 October 2011 - 10:25 AM





MultiQuote






|