Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control screen coordinate from Click event?

Status
Not open for further replies.

rcloutie

Programmer
May 26, 2005
164
CA
Hi all,

How to get the real screen coordinate (Top,Left) of a control (TBitBtn) from within the Click event?

When using MouseDown event, X and Y parameter are the mouse pointer coord and using ClientToScreen to convert points work but not the way I want to...

All this to display a TPopupMenu just under a TBitBtn (that is mnu.Left=btn.Left; mnu.Top=btn.Bottom)

Any ideas?

Thanks in advance...
 
Is this what you are looking for?

This pops up the menu right below the button:

ButtonPopup.Popup(self.Button.ClientOrigin.X , self.Button.ClientOrigin.Y + self.Button.Height);
 
Something like this:

Code:
procedure TMyForm.MyButtonMouseDown(Sender: TObject; 
                                    Button: TMouseButton;
                                    Shift: TShiftState;
                                    X, Y: Integer);
  var
    Point : TPoint;
  begin
    GetCursorPos(Point);
    Point.X := Point.X - X;
    Point.Y := Point.Y + Y;
    MyPopupMenu.Popup(Point.X, Point.Y);
  end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top