resizing form in constructor

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my forms constructor I have the following:

this.WindowState = FormWindowState.Maximized;

I then try to size some controls based on the size of the maximized form's
client area:

SomeControl.Height = (this.ClientSize).Height;

But this never returns the proper value i.e. (this.ClientSize).Height is
always too small (around 230 pixels). What is going wrong?
 
Lionel said:
In my forms constructor I have the following:

this.WindowState = FormWindowState.Maximized;

I then try to size some controls based on the size of the maximized form's
client area:

SomeControl.Height = (this.ClientSize).Height;

But this never returns the proper value i.e. (this.ClientSize).Height is
always too small (around 230 pixels). What is going wrong?


Hi,
After the intializecomponents() function only each control height and width
value will assign
try
form_load event other wise try after form.show() function call the same
code

Regards
sambath R
 
Hi Lionel,

Control class provides event Layout that is meant to be used exactly in this
scenarios. The event is fired whenever a control needs to reposition its
children elements.

In your form you can handle this event overriding the OnLayout method. Don't
forget to call the base class in order the form to fire the event so other
interested parts can have chance to process it.

HTH
 
Back
Top