以下是一个在一个Picture1中移动Picture2的例子Option Explicit Dim OldX As Single, OldY As SinglePrivate Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button And vbLeftButton Then OldX = X: OldY = Y
End SubPrivate Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button And vbLeftButton Then If Picture2.Top + Y - OldY > Picture1.Height - Picture2.Height And Picture2.Top + Y - OldY <= 0 Then Picture2.Move Picture2.Left, Picture2.Top + Y - OldY If Picture2.Left + X - OldX > Picture1.Width - Picture2.Width And Picture2.Left + X - OldX <= 0 Then Picture2.Move Picture2.Left + X - OldX End If End Sub
Dim OldX As Single, OldY As SinglePrivate Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button And vbLeftButton Then OldX = X: OldY = Y
End SubPrivate Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button And vbLeftButton Then
If Picture2.Top + Y - OldY > Picture1.Height - Picture2.Height And Picture2.Top + Y - OldY <= 0 Then Picture2.Move Picture2.Left, Picture2.Top + Y - OldY
If Picture2.Left + X - OldX > Picture1.Width - Picture2.Width And Picture2.Left + X - OldX <= 0 Then Picture2.Move Picture2.Left + X - OldX
End If
End Sub