Recent

Author Topic: [SOLVED] Center 2nd Form on Main Form  (Read 4214 times)

tudi_x

  • Hero Member
  • *****
  • Posts: 532
[SOLVED] Center 2nd Form on Main Form
« on: December 05, 2016, 03:59:53 pm »
Hi!
I am using the poMainFormCenter option in Lazarus 1.6.2 32b on Windows 7 64b when creating a second form as per attached project.
Unfortunately the second form is not centered to the main form and shows as per attached.
Please advise what I am missing.

Thank you!
« Last Edit: December 05, 2016, 08:26:05 pm by tudi_x »
Lazarus 2.0.2 64b on Debian LXDE 10

mig-31

  • Sr. Member
  • ****
  • Posts: 305
Re: Center 2nd Form on Main Form
« Reply #1 on: December 05, 2016, 04:12:44 pm »
Hi,

remove it Form2 from autocreate Form list.

Add code for example to TButton.Onclick:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   AForm2:TForm2;
  4. begin
  5.   AForm2:=TForm2.Create(Self);
  6. end;          
  7.  
Lazarus 2.2.6 - OpenSuse Leap 15.4, Mageia 8, CentOS 7

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: Center 2nd Form on Main Form
« Reply #2 on: December 05, 2016, 05:02:08 pm »
Thank you, the form is centered when there is no method on the On Show event.

If I assign a method to the On Show event the second form does not center the main, regardless where the poMainFormCenter option is set, in code or Object Inspector.
Code with method is attached.
Please advise.

Lazarus 2.0.2 64b on Debian LXDE 10

davect

  • New Member
  • *
  • Posts: 28
Re: Center 2nd Form on Main Form
« Reply #3 on: December 05, 2016, 05:24:30 pm »
Use poOwnerFormCenter instead of poMainFormCenter.

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: Center 2nd Form on Main Form
« Reply #4 on: December 05, 2016, 08:25:51 pm »
Thank you.
It worked with poOwnerFormCenter, although with some tweaks in some code (ex. use Screen Center in Object Inspector and Owner Form Center in code) and directly in other code.
Lazarus 2.0.2 64b on Debian LXDE 10

 

TinyPortal © 2005-2018