21
votes

I've a strange problem regarding auto sizing of a panel in a user control. This panel is anchored to all 4 sides of the user control. But the anchoring not always works as it should:

If the user control is resized by resizing the form, the right and bottom anchors don't work. But if the control is resized by using a splitter which is in the form, it works correctly. All other controls which are also affected by resizing work correctly, just this panel won't do.

I can't see the difference between resizing through a splitter and through a form.

Setting the size manually in the OnResize of the UserControl only works if the resizing is done by moving the splitter. If the resizing occurs by resizing the form, the heigth and the width of the panel won't change to the new values.

Edit: To make it more clear: The user control is added to a TabPage and set to Dock=DockType.Fill.

Edit2: To make it more complicated: This is the hierarchy the control is used: The Form contains a splitter with 2 controls (A and B). (B) contains a user control (C) with a splitContainer. The split container->panel1 in (C) contains a tabcontrol (D). This tabcontrol (D) contains a user control (E) (in a tabpage) . This user control (E) has a splitcontainer (F) in which another usercontrol with a tabControl (G) is placed. This tabcontrol (G) has tabpages, and in this pages is the described user control (H) placed.

If I place the control (H) directly to the panel in the splitcontainer (C) everything works fine. Since all controls which are added to a splitcontainer or a tabpage are set to docktype=fill, I cannot see why the last control has this problems.

Is there any limitation in the Windows Forms framework which limits the amount of child controls?

Edit: I have uploaded a TestApplication with which you can reproduce this issue. http://rapidshare.de/files/49092516/TestApplication.zip.html It occurs only under Vista. Win XP and 7 work properly... If you resize the form, the textBox with the "..." button won't resize, but if you resize via the vertical splitContainer, it works.

3
Could you paste the code code generated by the designer (where it links all the controls together)? My first guess is that your panel is anchored to a different control than you think (e.g. one of the panels of the split)Grzenio
That would be way too much code to paste, but I checked the anchor more than once and it is set correctly (which is proven by a working resizing when using the splitter)Jan-Patrick Ahnen

3 Answers

36
votes

There is a bug with deep nesting where the kernel runs out of stack space causing resizing, docking and anchoring to fail silently.

See https://web.archive.org/web/20140818095718/http://support.microsoft.com/kb/953934

2
votes

You have talked about both "anchor" and "dock", which can serve similar purposes but act differently. Your problem may be that you are trying to do both, and this is interfering with the behavior you want. If not, perhaps try switching from the one to the other.

It sounds like you've double checked the ansectery of the control, but did you examine it with: View->Other Windows->Document Outline (a very handy tool I only recently discovered)?

Finally, while it doesn't directly solve your problem, it sounds like you have a very complicated UI, and your users may benefit if you were to spend some time to consider if you could simplify the UI. Of course, I don't know your users or the purpose of the app, and what you have may be the best, but it sounds like it might be time to ask this question.

Good luck.

1
votes

The problem is not the depth of nesting; controls can be nested arbitrarily deep. Anchoring and Docking generally do not play nicely with each other. I usually favor docking over anchoring, but, whichever solution you choose, you should probably avoid mixing them.