Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help with Tpoint and location on my form

Posted on 2014-09-04
11
Medium Priority
?
182 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 28

Accepted Solution

by:
Sinisa Vuk earned 1600 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 400 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

876 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