Correct way to resize a control when form is resized

N

needin4mation

Is this the correct way to resize the controls on a form when the form
is resized?

protected override void OnResize(EventArgs ea)
{
listViewFiles.Width= this.ClientSize.Width-5;
lisInfoList.Width=this.ClientSize.Width-5;
}

What about buttons and other controls? Any links are appreciated.
 
N

Nicholas Paldino [.NET/C# MVP]

You might want to check out the Anchor property on the control. If you
set it, you can say "this side will expand when the container it is hosted
in expands". It saves you from having to write all that messy code
yourself.

Hope this helps.
 
C

Chris Dunaway

Have you checked into the Dock and Anchor properties of the controls in
question? Unless you require non-standard behavior, these properties
make it very easy to handle resizing.
 
N

needin4mation

I found them and got some of the items to work, but when, for example,
I maximize my window the buttons get huge for some reason. The
listview and listbox I have resized fine. thanks.
 
N

needin4mation

It is. I"m sorry guys. I should have found that one myself. I got
it. Thanks again.
 
U

Uchiha Jax

Don't worry about it. I sometimes get stumped for days on something that is
blatently obvious.
If one of us writing just a line of two of text saves you hours then thats a
good thing. :)

Jax
 
C

Chris Dunaway

I found them and got some of the items to work, but when, for example,
I maximize my window the buttons get huge for some reason. The
listview and listbox I have resized fine. thanks.

You probably have your buttons anchored on all four sides. Normally,
you only want buttons anchored to the top left or bottom right.
 
G

Guest

Chris Dunaway said:
Have you checked into the Dock and Anchor properties of the controls in
question? Unless you require non-standard behavior, these properties
make it very easy to handle resizing.

True as long as you don't need anything truely fancy. OTOH in my current
app there was an instance where resizing manually resulted in significantly
less flickering. The affected control is a multiline textbox inside a
manually resized groupbox.

If you have to do manual work plan on taking enough time to test multiple
approaches for each change, even though the code on your end is almost the
same the speed of what's being done by the framework might not be. In some
cases what looks like it should be the faster way might not be. IN my case
setting the Size property was faster than setting the width only and letting
anchoring handle the vertical sizing.
 

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