Search code examples
delphiribbon

How do I find the top and left of a button in the Delphi XE2 ribbon control?


The project I am working on has a demo mode which shows the user some of the features by moving the the mouse with setcursorpos to different controls. The position of the control is needed for the setcursorpos function. How do I find these for the tabs and buttons in a ribbon control?


Solution

  • AFAIK SetCursorPos needs screen related coordinates for the mouse position. Assuming the target control is named Button1 you get the screen coordinates of the top left corner with Button1.ClientOrigin;

    Update: Although not directly asked, it may be not clear how to get hands on the control instance representing the button. Let me take the RibbonDemo from the XE2 samples folder. The Delete button (index 3) on the Clipboard section can be accessed via rgHomeClipboard.ActionControls[3];