resizing form in constructor

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?
 
R

Robbe Morris [C# MVP]

size the controls in the Resize() event not the form load or
constructor.
 
G

Guest

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
 
S

Stoitcho Goutsev \(100\) [C# MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top