I need help with moving a form that has no titlebar.
I want to be able to grab a label and drag the form around with it.
Ive tried this but it doesnt work.
Code:
Dim DragOn As Boolean
Dim OldX As Single
Dim OldY As Single
Dim NewX As Single
Dim NewY As Single
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
DragOn = True
OldX = X
OldY = Y
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
DragOn = False
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If DragOn Then
NewX = X
NewY = Y
Me.Top = Me.Top + (NewY - OldY)
Me.Left = Me.Left + (NewX - OldX)
OldX = NewX
OldY = NewY
End If
End Sub
and this..
Code:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As _
Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Const HTCAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub