在 Form1 通用区定义变量:Dim Mx as long,My as long
1.需要移动的 picture2 控件要画在 picture1 控件中
picture2 的鼠标向下事件写入如下代码:
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Mx=x
My=y
End Sub
picture2 的鼠标移动事件写入如下代码:
Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
if button=1 then
if Mx-x>0 then picture2.left=picture2.left-Abs(Mx-x)'向左移
if Mx-x<0 then picture2.left=picture2.left+Abs(Mx-x)'向右移
if My-y>0 then picture2.top=picture2.top-Abs(My-y)'向上移
if My-y<0 then picture2.top=picture2.top+Abs(My-y)'向上移
end if
End Sub
我没有测试,你明白我的意思就行。