Click here to Skip to main content
15,884,473 members
Articles / Programming Languages / C#
Tip/Trick

MDI Forms that Minimize to Icons

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
29 Sep 2014CPOL2 min read 23.6K   1.8K   12   5
Shows how to implement minimize-to-icon for MDI Child forms

Minimizing MDI child form to icons demo

Introduction

WinForm MDI child windows do not minimize to icons. This article provides MDI Parent/Child classes that support minimize-to-icon functionality.

Background

Standard MDI application allows Child forms to be minimized. Alas, child windows minimize to a mere rectangle:

Stands MDI child form minimization

This article combines Forms Regions and MDI Parent/Child logic, to allow child windows to be minimized to Icons.

Using the Code

The code includes two classes: MinimizableForm and MinimizingFormParent.

The parent Form inherits from MinimizingFormParent, and the child form inherits from MinimizableForm.

C#
// MDI Parent 
public partial class <MDI Parent class name> : MinimizingFormParent
C#
// MDI Child
public partial class <MDI Child class name> : MinimizableForm

Included are two templates, a Minimizing MDI VS2013 Project Template, as well as Minimizing MDI Child Form VS2013 Item Template. These should be placed under %UserProfile%\Documents\Visual Studio 2013\Templates\ProjectTemplates and %UserProfile%\Documents\Visual Studio 2013\Templates\ItemTemplates respectively.

These templates facilitate creating an initial project, as well as allowing additional MDI Child Forms to be added.

Points of Interest

Reference

Setting the Child's Form region is a critical part of the solution (See the excellent article by Weiye Chen, Creating Bitmap Regions for Forms and Buttons, which serves as basis for this code.) Another is tracking/locating the minimized child windows.

MDI Child List Menu Item

MDI Child window list is automatically built using the MenuItem property (note a similar property exists for classic MDI children, using the MenuStrip MdiWindowListItem property.)

MDI Child list menu item

Code Support

The new Parent MDI form (MinimizingFormParent), supports the LayoutMDI method. Child form state is reflected (and may be modified) via MinimizableForm.WindowState

Constructors

The child form supports multiple Icon sources, and thus has multiple constructors:

C#
// This is the default constructor. It defaults to icons size of 128x128.
MinimizableForm()
C#
// Use Form's Icon. Make minimized icons size "iconSize".
MinimizableForm(int iconSize)
C#
// Construct using provided BMP or PNG file. PNG file may contain transparency,
// while pixel(0,0) will be used as transparency colour for BMP file.
MinimizableForm(String iconFile)
C#
// COnstruct using provided Bitmap. Use pixel(0,0) as transparency.
MinimizableForm(Bitmap iconBitmap)

Child Area

(This is well known...) The MDI Parent hosts all MDI children under a MdiClient control. MDI child windows live under this control, whose size is MdiClient.DisplayRectangle.Size. This, rather than MdiParent.ClientRectangle should be used when placing icons, as well as tiling client windows.

History

  • September 26th, 2014 -- Original version
  • September 27th, 2014 -- Added Project/Item Templates

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Bezeq International
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionAdd Child name under the icon Pin
gMagnus8731-Aug-17 17:38
gMagnus8731-Aug-17 17:38 
QuestionNice Baruch! Pin
Volynsky Alex29-Sep-14 12:12
professionalVolynsky Alex29-Sep-14 12:12 
QuestionPlain MDI applications are outdated... Pin
Philippe Mori28-Sep-14 2:47
Philippe Mori28-Sep-14 2:47 
In many cases, tabbed MDI interface can be a good alternative. You can then have an application with a behavior similar to Internet Explorer or almost any other browser.

There are many other possibilities depending on the type of application and the component you uses.

The almost single advantage of traditionnal MDI is that you don't need any third party component if you are developping for WinForms...
Philippe Mori

AnswerRe: Plain MDI applications are outdated... Pin
dduster28-Sep-14 3:50
professionaldduster28-Sep-14 3:50 
GeneralRe: Plain MDI applications are outdated... Pin
Kawaoneechan29-Sep-14 7:30
Kawaoneechan29-Sep-14 7:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.