tags:

views:

1685

answers:

7

It's been a while since I've programmed a GUI program, so this may end up being super simple, but I can't find the solution anywhere online.

Basically my problem is that when I maximize my program, all the things inside of the window (buttons, textboxes, etc.) stay in the same position in the window, which results in a large blank area near the bottom and right side.

Is there a way of making the the elements in the program to stretch to scale?

+3  A: 

Anchor and Dock properties

Steven A. Lowe
A: 

Are you using any layouts on the form?

itsmatt
A: 

Look at the Dynamic Layout: Anchoring and Docking sample at http://msdn.microsoft.com/en-us/library/aa289756(VS.71).aspx

It's in VB, but the concepts and the propeties/methods you need are the same in C#.

Franci Penov
+3  A: 

You want to check and properly set the Anchor and Dock properties on each control in the Form. The Anchor property on a control tells which sides of the form (top, bottom, left, right) the control is 'anchored' to. When the form is resized, the distance between the control and its anchors will stay the same. This lets you make a control stay in the bottom right corner for example.

The Dock property instructs the control to fill the entire parent form or to fill one side of it (again top, bottom, left or right).

Brian Ensink
A: 

I see the anchor and dock properties, so it looks like that this is answered.

As to layouts, I'm not quite sure what you mean, but I'm using Visual Studio 2008's default GUI editor.

Anyway, thanks for the help! Super fast responses. O.o

Dropped.on.Japan
A: 

There are some layout panel controls that help you keep things proportioned as the form expands/contracts:

TableLayoutPanel
FlowLayoutPanel

Joel Coehoorn
A: 

As to layouts, I'm not quite sure what you mean, but I'm using Visual Studio 2008's default GUI editor.

There are some special 'container' type panels that you could stick on your form such as FlowLayoutPanel and TableLayoutPanel. These types of containers have additional layout behavior.

If you find that some of your controls still don't want to behave during resize, then use the right-click context menu of the control to list the controls ancestors: its parent, its parent's parent, etc. You may find that the troublesome control is a child of some special container which has its own layout rules.

Brian Ensink