This little code snippet demonstrates how to include various docked controls on your MDIParent form and then dynamically force the MDIClient to respect the available docking space when set to DockStyle.Fill at runtime. |
The docking order in windows forms .net and the management thereof has always been a sore spot for me. The technique below is one way to get around the limitations of what can exist on a parent MDI form while still rendering the MDIClient properly.
What I did here was set the MDI Parent to NOT be an MDI container in the Visual Studio .NET 2005 Designer. I put all my various controls and docked them as needed. Then, in my form's constructor, I set the form to be an MDIParent at runtime. All that was then needed was to find the MDIClient (dynamically created for us by .NET) and set it to fill the remaining docking space. This appears to force the MDIClient to respect the existing docking orders of the previously created controls. public Form2()
{
InitializeComponent();
this.IsMdiContainer = true;
MdiClient client = null;
foreach (Control control in this.Controls)
{
if (control.GetType() == typeof(MdiClient))
{
client = (MdiClient)control;
client.Dock = DockStyle.Fill;
return;
}
}
} |
 |
| Biography - Robbe Morris |
| Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of EggHeadCafe.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice. |
|
|
|
Didn't Find The Answer You Were Looking For? |
| EggHeadCafe has experts online right now that may know the answer to your question. We pay them a bonus for answering as many questions as they can. So, why not help them and yourself by becoming a member (free) and ask them your question right now? |
| Ask Question In Live Forum |
|
| If you have an OpenID and do not want to become a member of the EggHeadCafe forum, you can also sign on to Chat Chaos and post your question to our real time Silverlight chat application. |
| Ask Question In Chat Chaos |
|
| Article Discussion: MDI .NET Forms Include Docked Controls And Smaller MDIClient |
| Robbe Morris posted at Tuesday, June 05, 2007 3:00 PM |
 | Original Article |
 |
| |
|