search
Japanese Chinese Nederlands Espanol Italiano Deutsch Francais Twitter Rss Feeds
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

Web ProgrammingArticlesForumsFAQs
JavaScript
ASP
ASP.NET
Web Services

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Operating SystemsArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

MDI .NET Forms Include Docked Controls And Smaller MDIClient


By Robbe Morris
Printer Friendly Version
View My Articles
14 Views
    

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.

button
Article Discussion: MDI .NET Forms Include Docked Controls And Smaller MDIClient
Robbe Morris posted at Tuesday, June 05, 2007 3:00 PM
Original Article