Solved

Help with Tpoint and location on my form

Posted on 2014-09-04
11
161 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
Comment Utility
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
Comment Utility
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
Comment Utility
Please show your code on positioning the wizard you have atm.
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
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
Comment Utility
With this code, the result is what we see in the first image?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:hidrau
Comment Utility
Yeah
0
 
LVL 19

Expert Comment

by:MerijnB
Comment Utility
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
Comment Utility
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 25

Accepted Solution

by:
Sinisa Vuk earned 400 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Solved.

thanks very much :)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 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

9 Experts available now in Live!

Get 1:1 Help Now