Link to home
Start Free TrialLog in
Avatar of panJames
panJames

asked on

Position relative to screen not to parent

Hello Experts :-)

I want to open form positioned just above clicked button.

So, what I need is the position of the button itself but not relative to its parent but to the screen.


I know that I can add position of the form, position of my button's parent and button itself but

maybe there is any better way of doing it?

Thank u very much :-)

panJames
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

is that what you looking for?

procedure TForm1.Button1Click(Sender: TObject);
var p: TPoint;
begin
  p := Point(Button1.Left + Button1.Width, Button1.Top + Button1.Height);
  p := ClientToScreen(p);
  with TForm2.Create(nil) do begin
    Left := p.X;
    Top := p.Y;
    ShowModal;
  end;
end;


ziolko.
Avatar of panJames
panJames

ASKER

It works fine but only for Left property.

For some mysterious reason it does not work for Top property.

This is my code:

procedure ABC
var p : TPoint;
begin
  p := Point(btnAnalyse.Left + btnAnalyse.Width, btnAnalyse.Top);

  p := ClientToScreen(p);

  SelectAnalysisTypeForm.Left := p.X;
  SelectAnalysisTypeForm.Top := p.Y;

  if SelectAnalysisTypeForm.ShowModal = mrOK then
  begin

  end;
end;

panJames
and what about this?

Point(btnAnalyse.Left + btnAnalyse.Width, btnAnalyse.Top + btnAnalyse.Width);

ziolko.
SOLUTION
Avatar of SteveBay
SteveBay
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
this change:

Point(btnAnalyse.Left + btnAnalyse.Width, btnAnalyse.Top + btnAnalyse.Height);

made my form appear lower by only btnAnalyse.Height value.

My form always appears on the top of the screen even when button clicked is rather close to the bottom of the screen.

panJames
I have an idea...

Maybe ClientToScreen considers as Client only parent of the button not the whole form?
The button's parent is actually a TPanel located on the bottom of the form.

Is it possible?

panJames
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I called it Panel1.clienttoscreen() and it works!

Thank u Mr ziolko :-)
And SteveBay too :-)