Recent

Author Topic: How to assign Form1.WindowsState:=wsMaximized  (Read 6203 times)

asdf

  • Sr. Member
  • ****
  • Posts: 310
How to assign Form1.WindowsState:=wsMaximized
« on: February 22, 2011, 04:06:27 pm »
procedure TForm1.FormCreate(Sender: TObject); 
Form1.WindowState:=wsMaximized; // Form1 stretched out in full screen so well.
Panel1.Top:=8; // this line worked well.
Panel1.Left:=8; // this line worked well.
Panel1.Width:=Form1.ClientWidth-16; // Panel1.Width didn't work.

But why did it work in procedure TForm1.FormShow(Sender: TObject);  ?

And what are the differences between procedure TForm1.FormCreate(Sender: TObject);  and procedure TForm1.FormShow(Sender: TObject); ?
 



   
Lazarus 1.2.4 / Win 32 / THAILAND

eny

  • Hero Member
  • *****
  • Posts: 1646
Re: How to assign Form1.WindowsState:=wsMaximized
« Reply #1 on: February 22, 2011, 04:11:07 pm »
Panel1.Width:=Form1.ClientWidth-16;

Don't have all the answers, but an easy fix for the above is using the Anchors property.
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

Lush

  • New Member
  • *
  • Posts: 15
Re: How to assign Form1.WindowsState:=wsMaximized
« Reply #2 on: February 22, 2011, 04:53:38 pm »
Hi,

I may be wrong but I believe ClientWidth is either undefined or doesn't hold the right value because there's no "outside context" when the onCreate event is triggered.

When the onShow event is fired, your form is placed inside its client (the screen I guess), and then the ClientWidth becomes available to your form.


Lush

Leledumbo

  • Hero Member
  • *****
  • Posts: 8799
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to assign Form1.WindowsState:=wsMaximized
« Reply #3 on: February 22, 2011, 07:02:44 pm »
Quote
And what are the differences between procedure TForm1.FormCreate(Sender: TObject);  and procedure TForm1.FormShow(Sender: TObject); ?
FormCreate is called AFAIR right after the form is created, in this method, the form handle exists, but the form not yet shown. FormShow is called AFAIR right before the form is shown.

I'm not really sure why it works in FormShow but not in FormCreate, my guess is the ClientWidth is different between those two methods. The calculation might be done in between.

 

TinyPortal © 2005-2018