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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Absolute position of a TComponent

Status
Not open for further replies.

metalchrist1984

Programmer
Sep 20, 2009
4
ES
Hello everybody.

My question is: Is there any way to read the absolute position in screen of a TComponent, for instance, a TImage?

The Top property is not useful for me. If it is 0, the component is in the relative position 0 of the TForm, but it is not the 0 absolute position in screen... (It depends on factors such as the title window height).

Thank you very much.
 
Perhaps you can synthesize the absolute position of a TImage in a screen. You do have access to the TForm's absolute position in the screen, so if you can determine the title window height, etc... you can determine the absolute position of a TImage.

Steve.
 
Thanks Steve,

but my problem is that i cannot determinate the height of the title window.

I can have the window in the position Top 0 and the TImage also in the position Top 0 (relative). If I knew the height of the title window the calculation of the absolute height position of the TImage would be as simple as:

abs_pos_h=TForm->Top+TitleWindowHeight+TImage->Top;

But I really do not know the height of the title window and I do not if it is possible to get it in some way, or calculate it.

Do you know how can get the height of the title window??

Thank you very much.
 
I guess if I was responsible for doing this sort of thing, I can think of five different things I would try:

1.) Experiment with title window heights: try 1, then try 2,...
2.) Remove the title bar altogether.
3.) Post this same question in the CodeGear(Borland) Delphi forum in 4.) Post this question on 5.) Explore the more of the TScreen class for some clues.


Sorry I am not being much help.

Steve.
 
Look at the Win32 API FindWindowEx() and GetWindowRect() function calls.

I believe the title bar is considered a child window (?), in which case perhaps you can get the dimensions of your title window(?).

Steve.
 
I think you might want check into the windows API function call ClientToScreen.
 
place in a TForm an TImage and a TButtom.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
TPoint point;
point = Image1->ClientToScreen(TPoint(0,0));
ShowMessage(AnsiString(point.x)+" "+AnsiString(point.y));
}

When you move the frame an push the buttom you will get the
absolute position.

If you replace Image1 with this (or Form1), you will get the absolute
position of the Form1
 
Thanks to you all, the ClientToScreen function is exactly what I was looking for.

Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top