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 Long) As Long
Dim G_Index As Integer
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
X = ReleaseCapture()
Call SendMessage(Picture1.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.MousePointer = 5
End Sub
Option Explicit
Dim dragx As Single
Dim dragy As Single
Const BEGIN_DRAG = 1
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
'如果所拖动的控件名称为"Command1"
If Source.Name = "Command1" Then
'将控件移动到指针所在位置
Command1.Move (X - dragx), (Y - dragy)
'控制
Command1.Visible = True
form2.Command1.Visible = False
End If
End Sub
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'记录指针在控件上的位置
dragx = X
dragy = Y
'开始拖动
Command1.Drag BEGIN_DRAG
End Sub
'在窗体加载是同时显示窗体form2
Private Sub Form_Load()
form2.Show
form2.Command1.Visible = False
End Sub
窗体2
Option Explicit
Dim dragx As Single
Dim dragy As Single
Const BEGIN_DRAG = 1
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
'如果所拖动的控件名称为"Command1"
If Source.Name = "Command1" Then
'将控件移动到指针所在位置
Command1.Move (X - dragx), (Y - dragy)
'控制
Command1.Visible = True
form1.Command1.Visible = False
End If
End Sub
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'记录指针在控件上的位置
dragx = X
dragy = Y
'开始拖动
Command1.Drag BEGIN_DRAG
End Sub