* * *

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

tudi_x

  • Full Member
  • ***
  • Posts: 208
[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 »

mig-31

  • Full Member
  • ***
  • Posts: 215
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 1.6 - Linux 32/64 bit, win32

tudi_x

  • Full Member
  • ***
  • Posts: 208
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.


davect

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

tudi_x

  • Full Member
  • ***
  • Posts: 208
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.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus