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

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
19 posts Page 1 of 2
User avatar
TheET
VIP-Member
VIP-Member
Posts: 105
Joined: Sun Nov 01, 2009 2:41 am

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 !
User avatar
TheET
VIP-Member
VIP-Member
Posts: 105
Joined: Sun Nov 01, 2009 2:41 am

Hope that helps ^^
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Very good job, indeed Newbie friendly tutorial.
User avatar
TheET
VIP-Member
VIP-Member
Posts: 105
Joined: Sun Nov 01, 2009 2:41 am

Thanks , thumbs up
User avatar
mylescomputer
Just Registered
Just Registered
Posts: 7
Joined: Fri Sep 04, 2009 7:39 pm

asom thxs
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

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
Last edited by hungryhounduk on Wed Nov 11, 2009 2:49 pm, edited 1 time in total.
Image
User avatar
bjm0008
Dedicated Member
Dedicated Member
Posts: 69
Joined: Thu Aug 13, 2009 2:35 am

Very nice, easy tutorial!
A++ wahooo;
Image
User avatar
TheET
VIP-Member
VIP-Member
Posts: 105
Joined: Sun Nov 01, 2009 2:41 am

Thanks
User avatar
Normall
Member
Member
Posts: 49
Joined: Wed Nov 25, 2009 9:25 pm

A bit too much code?
User avatar
Normall
Member
Member
Posts: 49
Joined: Wed Nov 25, 2009 9:25 pm

There ARE easier ways or shorter ways :P
19 posts Page 1 of 2
Return to “Tutorials”