我想在一个已经运行的用户窗体“解锁”一个固定的形象,这样我可以自由地走动,并再次点击它,因为它是在一个固定的位置后再次。
认为这样做,你在找什么。
Dim imgOriginX As Double
Dim imgOriginY As Double
Dim clicked As Boolean
Private Sub UserForm_Activate()
clicked = False
End Sub
Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If clicked = True Then
imgOriginX = X
imgOriginY = Y
End If
End Sub
Private Sub Image1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If clicked = True Then
clicked = False
Else
clicked = True
End If
End Sub
Private Sub Image1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If clicked = True Then
If Button And 1 Then
Image1.Left = Image1.Left + (X - imgOriginX)
Image1.Top = Image1.Top + (Y - imgOriginX)
End If
End If
End Sub