VBA在Rockwell Viw SE应用程序中。
我有一些有效的代码,但只有链接到鼠标按钮1时,我才真正需要它成为按钮2或鼠标右键单击功能。该代码位于MouseUp子菜单上,用于在屏幕上移动对象。我敢肯定,这只是VBA的一个怪癖,但我认为可能会有解决方法。
鼠标按钮2可以工作,但只有在与单击时在同一对象上释放时,鼠标按钮1才不在乎释放发生在屏幕上的什么地方。
Private Sub Box1_MouseUp(ByVal Button As DisplayClientEx.gfxMouseButtonConstants, ByVal Shift As Integer, ByVal X As Long, ByVal Y As Long)
Dim XObject As Object
Dim YObject As Object
FindNumStart = InStrRev(Box1.ToolTipText, "[") + 1
FindNumEnd = InStrRev(Box1.ToolTipText, "]")
BoxNum = Mid(Box1.ToolTipText, FindNumStart, (FindNumEnd - FindNumStart))
Set XObject = ThisDisplay.FindElement("XW" & BoxNum)
Set YObject = ThisDisplay.FindElement("YW" & BoxNum)
PNum = Box1.ToolTipText & ", " & Chr(34) & Mid(Box1.ToolTipText, 1, (FindNumStart - 14)) & "BoxPosition[" & BoxNum & Chr(34)
If Button = 2 Then
GetCursorPos Mouse
ScreenToClient Me.Application.WindowHandle, Mouse
Box1.Left = Mouse.X - 40
Box1.Top = Mouse.Y - 78
XObject.Value = Box1.Left
XObject.Download
YObject.Value = Box1.Top
YObject.Download
ElseIf Button = 1 Then
GetCursorPos Mouse
ExecuteCommand Cmd & " /X" & Box1.Left - 68 & " /Y" & Box1.Top + 100 & " /T " & PNum
End If
End Sub