MouseX and MouseY in 2021r3

Using the code Anthony kindly provided here with a few tweaks:

Public Function MouseX(extends r as DesktopUIControl) As Integer
  // For the control referenced, figure out the local MouseX position by walking up the containment hierarchy.
  Dim retValue As Integer = r.Window.MouseX - r.Left
  
  Dim p As Object = r.Parent
  
  Dim container As DesktopContainer
  
  While p <> r.Window
    if p isa DesktopUIControl then
      p = DesktopUIControl( p ).Parent
    ElseIf p IsA DesktopContainer Then
      container = DesktopContainer( p )
      retValue = retValue - container.Left
      p = container.Parent
    end if
  Wend
  
  Return retValue
End Function
4 Likes