Solved

Position relative to screen not to parent

Posted on 2007-12-04
8
573 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:panJames
  • 4
  • 3
8 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 20402225
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.
0
 

Author Comment

by:panJames
ID: 20402397
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
0
 
LVL 21

Expert Comment

by:ziolko
ID: 20402428
and what about this?

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

ziolko.
0
 
LVL 14

Assisted Solution

by:SteveBay
SteveBay earned 50 total points
ID: 20402977
ClientToScreen will not work because the title bar is not part of the the clent. You will need to add the difference between self.top and p.Y to get the true screen Y position.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:panJames
ID: 20403064
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
0
 

Author Comment

by:panJames
ID: 20403192
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
0
 
LVL 21

Accepted Solution

by:
ziolko earned 450 total points
ID: 20403222
clienttoscreen() is object method defined in TControl  so you can call it: form1.clienttoscreen()
ziolko.
0
 

Author Comment

by:panJames
ID: 20403435
I called it Panel1.clienttoscreen() and it works!

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now