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
Solved

Help with Tpoint and location on my form

Posted on 2014-09-04
11
177 Views
Last Modified: 2014-09-04
Hello Guys

I download this assistant

http://www.delphiarea.com/products/delphi-packages/assistant/

When I open it, I'd like it to show in the center of a specific panel.

But I don't know how to give the location where is my panel on my form,

I have this code from the assistent example, maybe it can give an idea how to.

var
  OldSize: TSize;
  Pos: TPoint;
begin
  Assistant.ActorLibrary := '';
  Assistant.OnGuideOptionsClick := nil; // To prevent re-entrance
  try
    //OpenDialog.FileName := Assistant.ActorLibrary;
    if OpenDialog.Execute and (Assistant.ActorLibrary <> OpenDialog.FileName) then
    begin

      OldSize.CX := Assistant.Width;
      OldSize.CY := Assistant.Height;
      Pos := Assistant.BoundsRect.TopLeft;
      Assistant.ActorLibrary := OpenDialog.FileName;
      Inc(Pos.X, (OldSize.CX - Assistant.Width) div 2);
      Inc(Pos.Y, (OldSize.CY - Assistant.Height) div 2);
      Assistant.SetPosition(Pos.X, Pos.Y);
      Assistant.Play([aaWave, aaGreet]);

    end;
  finally
  Assistant.Visible := True;
//    Assistant.OnGuideOptionsClick := SelectButtonClick;
  end;

Open in new window


As you can see, it has the SetPosition but I don't know how to get the x and y from my panel in my form.

thanks
0
Comment
Question by:hidrau
  • 5
  • 5
11 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 40303167
Not really sure, but I suspect you are looking for ClientToScreen().

See this example:

var aPoint: TPoint;
begin
 aPoint := Point(Panel1.Top, Panel1.Left);
 // now aPoint contains the X and Y position of your panel, relatively to your form
 aPoint := ClientToScreen(aPoint);
 // now aPoint contains the X and Y position of your panel, relatively to your screen
end;

Open in new window

0
 
LVL 1

Author Comment

by:hidrau
ID: 40303213
Hello MerijnB,

Please take a look at the image.

The wrong place

Wrong position of my assistant
The right place

Right Place in the middle of my panel
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 40303220
Please show your code on positioning the wizard you have atm.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:hidrau
ID: 40303236
I have this

var
  Pos: TPoint;
begin
  Assistant.ActorLibrary := '';
  Assistant.OnGuideOptionsClick := nil; // To prevent re-entrance
  Pos :=  Point(sPanel2.Top, sPanel2.Left); //Assistant.BoundsRect.TopLeft;
  Pos := ClientToScreen(Pos);
  Assistant.ActorLibrary := FileListBox1.FileName;
  Assistant.Play([aaWave, aaGreet]);
  Assistant.Visible := True;
  Assistant.SetPosition(Pos.X, Pos.Y);

Open in new window

0
 
LVL 19

Expert Comment

by:MerijnB
ID: 40303241
With this code, the result is what we see in the first image?
0
 
LVL 1

Author Comment

by:hidrau
ID: 40303251
Yeah
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 40303255
Seems you mixed op X and Y in your call to Point(), try this:

var
  Pos: TPoint;
begin
  Assistant.ActorLibrary := '';
  Assistant.OnGuideOptionsClick := nil; // To prevent re-entrance
  Pos :=  Point(sPanel2.Left, sPanel2.Top); //Assistant.BoundsRect.TopLeft;
  Pos := ClientToScreen(Pos);
  Assistant.ActorLibrary := FileListBox1.FileName;
  Assistant.Play([aaWave, aaGreet]);
  Assistant.Visible := True;
  Assistant.SetPosition(Pos.X, Pos.Y);
                                        

Open in new window

0
 
LVL 1

Author Comment

by:hidrau
ID: 40303271
Hummm, almost

Please, take a look at the image

img2.fw.png
Is there any way to center in the panel?

Like this

img2.fw.png
0
 
LVL 26

Accepted Solution

by:
Sinisa Vuk earned 400 total points
ID: 40303277
you need this:
....
Pos :=  Point(0, 0); 
Pos := sPanel2.ClientToScreen(Pos);
...

Open in new window


....centered:
....
Pos :=  Point((sPanel2.ClientWidth-Assistant.Width) div 2, (sPanel2.ClientHeight-Assistant.Height) div 2); 
Pos := sPanel2.ClientToScreen(Pos);
...

Open in new window

0
 
LVL 19

Assisted Solution

by:MerijnB
MerijnB earned 100 total points
ID: 40303299
I suspect you're currently not calling ClientToScreen() from the form, but from another control.
Probably Sinisa's code will give proper result, you can also use

  Pos :=  Point(sPanel2.Left, sPanel2.Top); //Assistant.BoundsRect.TopLeft;
  Pos := Form.ClientToScreen(Pos);

Open in new window


Where Form is obviously the name of your form.

Once we get the assistant in the panel we'll focus on centering it.
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 40303308
Solved.

thanks very much :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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