Solved

Position relative to screen not to parent

Posted on 2007-12-04
8
585 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
Technology Partners: 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 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
 

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

Technology Partners: 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!

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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month3 days, 14 hours left to enroll

630 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