运行 用户表单时移动形状
Moving a shape when running a userform
我正尝试在已经 运行 的用户窗体上 "unlock" 固定图像,以便我可以自由移动它,再次单击它后,使其再次处于固定位置.
认为这符合您的要求。
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
我正尝试在已经 运行 的用户窗体上 "unlock" 固定图像,以便我可以自由移动它,再次单击它后,使其再次处于固定位置.
认为这符合您的要求。
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