Solved

Help with Tpoint and location on my form

Posted on 2014-09-04
11
173 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

777 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