views:

301

answers:

3

I have a simple form that contains a TabControl where the TabPages are added at runtime. I have gotten all of this to work almost as I want it to, however when I set the form to autosize, it ignores the runtime TabPages in the calculation... How can I either force the form to delay the autosizing until the TabPages have been added, or force the form to recalculate when a new TabPage is added?

EDIT: For the record, I'm testing this out by starting my app at 640x480 (using the MinimumSize property) and including a control that is 750 wide.

A: 

Would using the SuspendLayout() and ResumeLayout() do the trick? Here's the link that explains how it works.

You call SuspendLayout() first, add the tab pages, then ResumeLayout().

Hope this helps, Best regards, Tom.

tommieb75
Unfortunately, that doesn't seem to affect the Autosize logic...
EvoGamer
A: 

What about using TabPage.Dock = DockStyle.Fill?

Lex Li
TabPages don't have a Dock property. It's up to the TabControl to Dock, which it already does.
EvoGamer
A: 

I suspect that you're no longer having this problem, but this might be helpful for anyone else searching for a solution. You can set the MinimumSize of the TabControl to be the MinimumSize of the largest TabPage that you add. TabPages don't have a MinimumSize of their own, so you'd have to have a single fully Docked control in the TabPage on which you could check the MinimumSize.

I already had this setup (using a FlowLayoutPanel to lay out the contents of the TabPage) so it was relatively simple, not sure if it would be so easy for others. I know it's a really unpleasant 'solution' to the problem, but I couldn't find another way of forcing the TabControl to update itself properly.

Gibsnag