I have a Form with only a single TabControl, with many tabs, where each tab has only square buttons side by side. I am trying to make it so that when the user clicks on a tab, the form resizes itself to a size where you can see all the buttons in a particular tab or a size where you can see all the tabs, whichever is greater.
I am just curious if there is a way to query where the last control in a tab page is? So I can just do something like:
tabForm.Width = currentTabPage.UsedContentBorder + 10;
Or do I have to do this by adding all the controls and the sizes between them, etc?
You want to find out the maximum coordinates of all controls in a specific tab? Easy with LINQ:
Now, to properly choose the size of the form, I imagine you just have to figure out how much larger the Form is than its TabPages… I would guess something like this:
Then you just do
(the TabControl will resize automatically if its
Anchorproperty is set to all four sides.) It occurs to me that this may malfunction if the user resizes the form very small… you may be able to compensate by calculating extraWidth and extraHeight in the Form.Load event and then saving those values for when you need them later.