Home » Coding Basics » How to move a Form without Title bar
How to move a Form without Title bar
Posted on August 25, 2009
On some occasions, your client may ask you to use the form without title bar and however, he will ask you to make the form movable. As there is no title bar, we need to capture the move move, mouse up and mouse down events and move the form. So, here is the piece of code that will help you to accomplish that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | Option Explicit Dim OldX As Integer, OldY As Integer Dim blnMove As Boolean Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) blnMove = True OldX = X OldY = Y End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If blnMove = True Then Me.Left = Me.Left + (X - OldX) Me.Top = Me.Top + (Y - OldY) End If End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Me.Left = Me.Left + (X - OldX) Me.Top = Me.Top + (Y - OldY) blnMove = False End Sub |
Enjoy this article?
Filed under: Coding Basics, Controls
Leave a comment