How do I do this?
Printable View
How do I do this?
In the dclaration section of your form:
And in the form:Code: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 Sub ReleaseCapture Lib "user32" ()
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
That's all.Code:Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 Then
ReleaseCapture
SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End If
End Sub
make a module (bas)
put this in the general declarations of the module:
then under that but not in the general declarations put:Code:Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Declare Function ReleaseCapture Lib "user32" () As Long
Public Const WM_NCLBUTTONDOWN = &HA1
Public Const HTCAPTION = 2
now you need a label in the form ... in the label's mousedown event type:Code:Public Sub MoveForm(frm As Form)
ReleaseCapture
X = SendMessage(frm.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0& )
----------------Code:MoveForm Me
i did not write this code - it does work but the credit doesn't belong to me ....
[Edited by theman32x on 08-26-2000 at 07:24 PM]
Here's how to do it without using API:
Code:Dim oldX As Long, oldY As Long, isMoving As Boolean
'^goes in form declarations
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
oldX = X
oldY = Y
isMoving = True
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If isMoving Then
Me.Top = Me.Top - (oldY - Y)
Me.Left = Me.Left - (oldX - X)
End If
End Sub
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
isMoving = False
End Sub
Try this:
Code:Private Declare Function ReleaseCapture Lib "user32" () As Long
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
Const WM_SYSCOMMAND = &H112
Const SC_MOVE_EX = &HF012
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
ReleaseCapture
SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MOVE_EX, 0
End If
End Sub