Board index » delphi » Absolute Screen Location of Component.

Absolute Screen Location of Component.

Some component don't have a POPup menu
So I want to implement it myself.
But PopUp requires me to give it the absolute co-ordinate, which I
don't know how to calculate it right, here I go as

(I want to put it right under SpeedButton39)

   PopupMenu3.Popup(Form2.Left+SpeedButton39.Left,  
           Form2.Top+                     // speed button is located
           TabSheet1.Top+            // in a tabsheet
           Panel4.Height+              // 2nd panel
           SpeedButton39.Top+SpeedButton39.Height);

I still cannot get it right, I think I left out the form's title bar
height.  How to calculate it?
Is there a simpler way to find out the exact location ??

Thanks

 

Re:Absolute Screen Location of Component.


Quote
In article <360f0e1c.4162...@News.hk.super.net>, and...@aelhk.com (Anders Lee) wrote:
>Some component don't have a POPup menu
>So I want to implement it myself.
>But PopUp requires me to give it the absolute co-ordinate, which I
>don't know how to calculate it right, here I go as
>(I want to put it right under SpeedButton39)
>   PopupMenu3.Popup(Form2.Left+SpeedButton39.Left,  
>           Form2.Top+                     // speed button is located
>           TabSheet1.Top+            // in a tabsheet
>           Panel4.Height+              // 2nd panel
>           SpeedButton39.Top+SpeedButton39.Height);
>I still cannot get it right, I think I left out the form's title bar
>height.  How to calculate it?
>Is there a simpler way to find out the exact location ??

Why not try TControl.ClientToScreen?

  ResultingPoint := SpeedButton39.ClientToScreen(0,SpeedButton39.Height)

Then use ResultingPoint.X and ResultingPoint.Y for your popup menu.

Hope that helps..

  --=- Ritchie Annand

Re:Absolute Screen Location of Component.


Quote
>Why not try TControl.ClientToScreen?

>  ResultingPoint := SpeedButton39.ClientToScreen(0,SpeedButton39.Height)

>Then use ResultingPoint.X and ResultingPoint.Y for your popup menu.

  Thanks Rich,
      I actually find ClientToScreen by an accident glance through the
menus.

  But I was stupid enough to use

   ResultingPoint :=SpeedButton39.ClientToScreen(0,0);
  Then add the button.height to the resulting Y coordinates.

  Yours example surely does it simpler.

  But then, I found out that using Button.ClientOrigin is even
simpler!

Other Threads