To have a better UI, programmers usually use a borderless form. But there's no caption bar and the form cannot be move. This code help you to move a form by clicking anything that support mousemove, mouseup, mousedown events. See it , it's cool!
Submitted On | |
By | Kenny Lai, Lai Ho Wa |
Level | Beginner |
User Rating | 5.0 (10 globes from 2 users) |
Compatibility | VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0 |
Category | VB function enhancement |
World | Visual Basic |
Archive File |
<<>>
Dim ism as boolean
Public Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub lbltitle_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
ism = True
x1 = x + lblTitle.Left
y1 = y + lblTitle.Top
End Sub
Private Sub lbltitle_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If ism = True Then
i = GetCursorPos(Pos)
x2 = Pos.x * Screen.TwipsPerPixelX
y2 = Pos.y * Screen.TwipsPerPixelY
Me.Move (x2 - x1), (y2 - y1)
End If
End Sub
Private Sub lbltitle_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Me.Top < 0 Then Me.Top = 0
If Me.Left < 0 Then Me.Left = 0
If Me.Top > (Screen.Height - (Me.Height / 10)) Then Me.Top = Screen.Height * 9 / 10
If Me.Left > (Screen.Width - (Me.Width / 10)) Then Me.Left = Screen.Width * 9 / 10
ism = False
End Sub