Maximize and resize Windows

J

javachallenge

Dear all,
I am a newby of .NET programming and I have a general question. If I
put some controls on a windows form (say with size 300,400), when I
resize the Window (enlarging it) or if I Maximize it, the controls
remain in the top left corner in the rectangle 300,400 making the whole
form look very bad.

If I resize Notepad, the multiline textbox within resizes too... I'd
like my applications do the same.

Are there techniques, articles, tutorials or something like that, that
can explain me how to handle this?

Thanks in advance. JC
 
B

Bajoo

Dear JC,
You are facing a Layout problem. If you are using .Net v1.1
then you have to use some 3rd party Layout Library for layout. Incase
you are using VS2005/.Net v2 , Microsoft has provided Layout Controls.

Regards,
Naveed Ahmad Bajwa
http://bajoo.blogspot.com/
 
S

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

Hi,

There are two easy ways of doing this.
1. Use control docking (not to be mistaken with docking winodws found in the
most of the UI frameworks including WindowsForm in .NET 2.0).
Each winform control has property *Dock* this property specifies how the
control is aligned within its container. When controls are docked left, top,
right or bottom they stick to the specified side of the container and move
and resize accordingly when the size of the container changes. With these
four docking styles one of the control dimension can be set the other
depends on the rest the surrounding docked controls in the contianer. For
example if you dock a control *Top* the control is aligned against the upper
border of the container, its width is determined by the current docking
configuration and its height can be set.
The last added control to the container can be docked Fill which means to
fill the whole left not occupied by other controls space. Apparently the
size of the control is controlled by the framework and cannot be set neither
at runtime nor at design time. The Fill mode is actually what you are after.

2. Along with the Dock property controls provide *Anchor* property. It comes
into play when the Dock is set to *None*. This property specifies that
position of some sides of the control are fixed. For example if a control is
anchored Bottom-Right the positions the bottom and the right sides are fixed
and the distance between the left border of the container and left border of
the control as well as between the bottom of the container and bottom of
the form will remain the same as the form resizes. The efect will be that
the control will move along.
By anchoring the four sides of the control you will get the result of
resizing the control along withe the form.

My personal preference is to use docking when designing the main form of an
application, even thought in VS2003 doesn't make easy for us to manage the
docking order when new control is added to the form or other container.
Anchoring comes handy when designing dialog boxes want ot allow resizing.
 

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