Solved

Position relative to screen not to parent

Posted on 2007-12-04
8
572 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

18 Experts available now in Live!

Get 1:1 Help Now