Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Position relative to screen not to parent

Posted on 2007-12-04
8
Medium Priority
?
586 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Assisted Solution

by:SteveBay
SteveBay earned 200 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
 

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 1800 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

722 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