开发者

C# TabPages added at runtime don't autosize the parent form

开发者 https://www.devze.com 2022-12-18 04:18 出处:网络
I have a simple form that contains a TabControl where the TabPages are added at runtime. I have gotten all of this to w开发者_JS百科ork almost as I want it to, however when I set the form to autosize,

I have a simple form that contains a TabControl where the TabPages are added at runtime. I have gotten all of this to w开发者_JS百科ork 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.


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.


What about using TabPage.Dock = DockStyle.Fill?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消