Option Explicit
'*****************************************移动窗体
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 Integer, ByVal lParam As Long) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Call DragKj(Me.hwnd)
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Call DragKj(Picture1.hwnd)
End Sub
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Call DragKj(Text1.hwnd)
End Sub
Public Sub DragKj(HwndKj As Long)
On Error Resume Next
Call ReleaseCapture
Call SendMessage(HwndKj, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End Sub
1、
Dim t, tx, ty
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
t = True
tx = X
ty = Y
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If t = True Then
Form1.Top = Y + Form1.Top - ty
Form1.Left = X + Form1.Left - tx
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
t = False
End Sub