2
votes

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.

3
What happens if you turn autosizing off and then back on after adding the tab?Jay

3 Answers

0
votes

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.

0
votes

What about using TabPage.Dock = DockStyle.Fill?

0
votes

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.