I have some code that is working but only if linked to mouse button 1 and I really need it to be a button 2 or right mouse click function. The code is on the MouseUp sub and is used to move an object on screen. I’m sure it’s just a quirk of VBA but thought there may be a workaround.
Mouse button 2 will work but only if released over the same object as when clicked, mouse button 1 don't care where on the screen the release happens.
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
Mouse button 2 will work but only if released over the same object as when clicked, mouse button 1 don't care where on the screen the release happens.
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