Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: Anchored Panel won't resize properly

Tags:

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.

like image 561
Jan-Patrick Ahnen Avatar asked Feb 01 '10 11:02

Jan-Patrick Ahnen


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

Why do we write C?

We write C for Carbon Because in some element the symbol of the element is taken form its first words and Co for Cobalt beacause in some elements the symbol of the element is taken from its first second letters, so that the we don't get confuse.


2 Answers

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

like image 167
Nick Avatar answered Sep 30 '22 18:09

Nick


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.

like image 36
Andy Jacobs Avatar answered Sep 30 '22 17:09

Andy Jacobs