Home > Articles > Programming > .NET and Windows Programming

Understanding MDI Applications in .NET

  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Close Window

Peter Aitken

Learn more…

Debugging 101 for Visual Studio
Sep 15, 2006
Fun with Fractals in Visual Studio .NET
Aug 11, 2006
Exploring Excel Functions, Part 9: Analyzing Frequency Distributions
Aug 4, 2006
File Management in .NET
Jul 7, 2006
Exploring Excel Functions 8: Predicting the Future
Jun 30, 2006
Exploring Excel's Functions, Part 7: Rounding with Excel
Jun 23, 2006
Binary File Access in the .NET Framework
Jun 16, 2006
Text File Access in the .NET Framework
Jun 2, 2006
Using Geometric Transforms for Text Effects in .NET
May 26, 2006
Understanding MDI Applications in .NET
May 12, 2006
A .NET Framework Text and Font Primer
Apr 21, 2006
Exploring Excel's Functions, Part 6: TTEST() Function
Apr 14, 2006
Troubleshooting Excel PivotTables
Apr 7, 2006
Troubleshooting Word Tables
Mar 31, 2006
Exploring Excel's Functions, Part 5: The Power of Choice
Mar 24, 2006
Seven Things I Hate About Word Printing
Mar 10, 2006
Exploring Excel's Functions, Part 4: Database Functions
Feb 24, 2006
Exploring Excel's Functions Part 3: CELL() Shocked
Feb 3, 2006
Exploring Excel's Functions Part 2: ADDRESS() and INDIRECT()
Dec 30, 2005
Exploring Excel's Functions: IF() Only!
Dec 9, 2005
Advanced Find-and-Replace Tools in Word
Oct 28, 2005
Going Beyond Basic Spaces and Hyphens in Word
Sep 16, 2005
Get Organized with Word's Outline Tools
Aug 19, 2005
Managing Your Money in Microsoft Excel: Basic Financial Calculations
Jul 29, 2005
Structured Exception Handling in Visual Studio .NET
Oct 8, 2004
Multithreading with the .NET Framework
Jun 11, 2004
.NET Tools for Working with XML
May 21, 2004
Storing Information: Variables and Constants in C
Mar 28, 2003
Introducing Web Programming with .NET
Mar 1, 2002
Using Web Forms
Mar 1, 2002
Introducing Web Services
Feb 15, 2002
XML and the .NET Framework
Feb 8, 2002
ASP.NET Programming: Using Web Forms
Jan 25, 2002
Understanding the Common Features of Web Controls
Aug 20, 2001

Sorry, this author hasn't posted any blogs.

The multiple document interface (MDI) is handy when your program needs to open multiple documents of the same kind. Peter Aitken shows how to take advantage of the MDI support built right into the .NET Framework.

Form Basics

Many Windows applications use a multiple document interface (MDI). I’m sure you’ve used one yourself—Excel and Photoshop are just a couple of examples of commercial MDI apps. But what exactly is special about MDI?

The MDI interface is designed for applications that need to have two or more documents open at the same time. The documents are independent of each other and have different content, but they’re the same type of document, such as an Excel workbook or a Photoshop image. An MDI application provides a single parent window—called the MDI parent form—with each open document represented by a child form. This arrangement has some special characteristics:

  • Child forms are restricted to the parent form’s client area.
  • Minimizing/restoring the parent automatically minimizes/restores the children.
  • The application’s menu and/or toolbar are hosted in the parent form.
  • Only one child can be active at a time, and user input and commands are automatically routed to that active child form.

An MDI child form can contain controls and other components, just like a regular form. The parent form is typically limited to menu and toolbars. In most MDI applications, all child forms are instances of the same class—a class designed to work with the application’s documents, whatever they may be. An MDI parent is not limited to showing child forms; it can also display standard forms/dialog boxes that are not in the special MDI parent/child relationship.

Creating the Parent Form

In most respects, an MDI parent form is like any other form. At design time, all you need to do is set its IsMdiContainer property to True. The form’s background color is automatically set to a dark gray when you do this, but you can change that color if desired.

Creating Child Forms

Nothing different is required when creating a child form. Its child relationship with the MDI parent is set in code when the form is instantiated, not at design time. All that’s required is to set the form’s MdiParent property to refer to the parent form. You’ll see an example later.

Creating a Document List

It’s standard practice for an MDI application to present a list of all open documents from which the user can choose. Traditionally, this is done on a Window menu, and this task can be automated as follows:

  1. Place a MenuStrip control on the parent form.
  2. Add a Window item to the MenuStrip control.
  3. Set the MdiWindowListItem property of the MenuStrip control to refer to the Window menu item.

Yep, it’s that simple. The framework will automatically display a list of all open documents on the Window menu, below any other items on that menu, using whatever names you’ve assigned to the Text property of each form. Don’t you just love it when your programming tool makes your life so much easier?

  • Share ThisShare This
  • Your Account

Discussions

Make a New Comment

You must log in in order to post a comment.

Related Resources

Jennifer  BortelWin FREE iPhone Developer Books and Videos- Introducing @InformIT Giveaways
By Jennifer Bortel on February 5, 2010 No Comments

Apples’s recent iPad announcement made our hearts flutter so we couldn’t resist making an announcement of our own!

Today marks the first ever @InformIT Giveaway!

We’ll regularly post a video like this one profiling spectacular prizes we’re giving away—from books and videos to T-shirts and other exciting stuff. Check out the video below to see the giveaways for today, and then scroll down for more prize details and instructions on how to win them!

Dustin Sullivan"Every OSX developer should have this book on their desk."
By Dustin Sullivan on February 1, 2010 No Comments

That was the sentence Mike Riley ended his recent Dr Dobb's CodeTalk review of Cocoa Programming Developer's Handbook with.

David ChisnallCocoa Tip of the Day, 1/29/10
By David Chisnall on January 29, 2010 No Comments

Don't ignore old versions of OS X.

See All Related Blogs

Informit Network