Page 1 of 2

How to move a borderless form in VB 08 [Tutorial]

Posted: Sun Nov 01, 2009 3:09 am
by TheET
Newbie friendly Tutorial
Here's a rare tutorial which a lot of people don't know , this tutorial will teach you how to move your form when you set your form border to NONE ( A borderless form cannot move )

What can you do with a borderless form ?
You can add any beautiful or amazing designs to your programs

First , you need to have Visual basic 2008 .

1.Open up your visual basic and select File > New Project (ctrl+N) > Windows Form Application > Name it anything you like :D
When successfully opened it , it will look like this :
Image

2.Select the form , set the "FormBorderStyle" to "None" that is in the form properties .
Image
This will make your form border to dissapear

3.Ok now , lets press debug , you can see that the form cannot move .

4.Ok , double click on the form and you will go into "Form1.vb" (The code page)
Then copy and paste the code below into Form1.vb (Paste it below "Public Class Form1"):


Dim NewPoint As New System.Drawing.Point()
Dim X, Y As Integer

Private Sub Form1_MouseMove1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If e.Button = MouseButtons.Left Then
NewPoint = Control.MousePosition
NewPoint.X -= (X)
NewPoint.Y -= (Y)
Me.Location = NewPoint
End If
End Sub

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
X = Control.MousePosition.X - Me.Location.X
Y = Control.MousePosition.Y - Me.Location.Y
End Sub

5.Ok , now press debug again and you can move the form !
:lol:

Hope that helps .
[Extra!]
If you want to add a close button , just add a button , double click on it , type in "Me.close" . Debug it and when you click on the button the form will close !

Re: How to move a borderless form in VB 08 [Tutorial]

Posted: Sun Nov 01, 2009 3:20 am
by TheET
Hope that helps ^^

Re: How to move a borderless form in VB 08 [Tutorial]

Posted: Sun Nov 01, 2009 11:27 am
by Nery
Very good job, indeed Newbie friendly tutorial.

Re: How to move a borderless form in VB 08 [Tutorial]

Posted: Sun Nov 01, 2009 12:57 pm
by TheET
Thanks , thumbs up

Re: How to move a borderless form in VB 08 [Tutorial]

Posted: Mon Nov 09, 2009 7:32 pm
by mylescomputer
asom thxs

Re: How to move a borderless form in VB 08 [Tutorial]

Posted: Mon Nov 09, 2009 7:54 pm
by hungryhounduk
Dont forget to let people know about setting the Transparency Key and back color of form to the same color... ie: a color that does not clash with the design your are using as the form Background.

Good post

Re: How to move a borderless form in VB 08 [Tutorial]

Posted: Wed Nov 11, 2009 1:42 pm
by bjm0008
Very nice, easy tutorial!
A++ wahooo;

Re: How to move a borderless form in VB 08 [Tutorial]

Posted: Wed Nov 18, 2009 8:56 am
by TheET
Thanks

Re: How to move a borderless form in VB 08 [Tutorial]

Posted: Wed Nov 25, 2009 9:54 pm
by Normall
A bit too much code?

Re: How to move a borderless form in VB 08 [Tutorial]

Posted: Wed Nov 25, 2009 9:56 pm
by Normall
There ARE easier ways or shorter ways :P