Solved

Help with Tpoint and location on my form

Posted on 2014-09-04
11
180 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
[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
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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 27

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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 …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month6 days, 14 hours left to enroll

623 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