views:

32

answers:

2

Dear reader,

I have a form that has several controls:

  • ProgressBar at the top of the form (docked)
  • A TabControl at the top of the form (also docked but underneath the progress bar)
  • Buttons, TextBoxes and labels inside TabPages of the TabControl
  • FlowLayoutPanel at the bottom of the screen (docked) with a few buttons in it
  • Label at the bottom of the form to act as separator (also docked, but above the FlowLayoutPanel)

I am trying to auto size the form to fit its content. What needs to happen is:

  1. Tab pages wrap around its content
  2. Tab control wraps around the largest tab page
  3. The form wraps around the tab control, progress bar and buttons.

Here's an example of how the form looks without AutoSizeMode set to GrowAndShrink (just Grow):

alt text

And this is how it looks with AutoSizeMode set to GrowAndShrink:

alt text

Please advise.

+1  A: 

To get this to work, you have to set the MinimumSize of all your controls to a value. This will be respected from the Shrink-Mode, thus leading to a well sized form.

Oliver
Unfortunately the content of the tab pages varies, so I can't really set a `MinimumSize` for that.
Kevin van Zanten
I'm not really sure, but if you set the MinimumSize of all elements within the TabPage, the TabPage itself should respect this.
Oliver
I understand. I think I'll just go for setting the form to a `MinimumSize`, because there are a lot of controls that are dynamically generated. I can't really set a size for all of them. Thanks though!
Kevin van Zanten
A: 

Make sure the direct children of your form have anchors set exactly to Left and Top. You could set the Form.MinimumSize Property and Form.MaximumSize Property as a precaution.

Jaroslav Jandek