65.9K
CodeProject is changing. Read more.
Home

MDI Forms that Minimize to Icons

starIconstarIconstarIconstarIconstarIcon

5.00/5 (3 votes)

Sep 27, 2014

CPOL

2 min read

viewsIcon

24307

downloadIcon

1760

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.

// MDI Parent 
public partial class <MDI Parent class name> : MinimizingFormParent
// 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:

// This is the default constructor. It defaults to icons size of 128x128.
MinimizableForm()
// Use Form's Icon. Make minimized icons size "iconSize".
MinimizableForm(int iconSize)
// 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)
// 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