Click here to Skip to main content
Click here to Skip to main content
Go to top

Check to see if an MDI Child is already active in an MDI Parent

, 20 Jul 2004
Rate this:
Please Sign up or sign in to vote.
A Simple boolean function to check if an MDI Child has already been loaded into an MDI Parent Container.

Introduction

This is a simple to implement function to determine if an MDI child has already been loaded into the MDI parent. You can then use a Switch, Select Case, or If Statement to choose what to do.

Background

I needed a solution to detect if an MDI Child Form has already been loaded into it's Parent Container. After some searching online, I found nothing.

Function Code

Place the following in your MDI Parent's form Class.

/* the String WndCls is the windows full path. Namespace.Classname */
internal bool CheckMdiClientDuplicates(string WndCls)
{
 Form[] mdichld= this.MdiChildren; 
 if (this.MdiChildren.Length == 0) 
 {
  return true;
 }
 foreach (Form selfm in mdichld) 
 {
  string str=selfm.Name;
  str = str.IndexOf(WndCls).ToString();
  if (str != "-1")
  {
   return true;
  }
 }
  return false;
}

Implementation

The following checks to see if the About MDI Child Form has been created. If it hasn't, it then creates it.
The Namespace for this Application is BTs and the Class Name for the About Form is AboutWnd.

 if (CheckMdiClientDuplicates("BTs.AboutWnd") == true){
 AboutWnd AboutWindow = new AboutWnd(this);
 AboutWindow.Show();
 }

Summary

Again, I didn't find anything on this with a quick search online. I've tried MSDN, Google and several others. It was time sensitive and imperative that this gets done and I hadn't the time to continue looking. However this function seems to work well and quickly.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication

Share

About the Author

GRMartin
Software Developer (Senior) Intrepid Pursuits
United States United States
Presently living in Massachusetts, i am a Mobile developer specializing in iOS and Adroid, with previous work in the Windows .NET world and Linux GTK.
Follow on   Twitter

Comments and Discussions

 
GeneralAvoid to open more than one windows. PinmemberV K Gupta25-May-09 23:11 
QuestionActive form Pinmemberthachvv1813-Jul-07 3:48 
AnswerRe: Active form PinmemberGiorgi Dalakishvili13-Jul-07 4:22 
GeneralRe: Active form Pinmembergaurav_pandya29-Jul-08 19:35 
GeneralGood Pinmemberdavarmanesh12-Jun-07 6:28 
Generalhelp... PinmemberGustavo Ushijima4-Mar-07 3:00 
QuestionUsing MDI Form Pinmemberm3n5428-Sep-06 0:52 
AnswerRe: Using MDI Form Pinmemberhhmiles214-Jan-07 17:38 
GeneralRe: Using MDI Form PinmemberGulkit Jain17-Nov-07 3:24 
Questionaccess parent form of showgialog window Pinmemberamilapradeep25-Sep-06 2:42 
AnswerRe: access parent form of showgialog window Pinmemberamilapradeep25-Sep-06 3:32 
GeneralVersion 2.0 of this function Pinmemberjaviersolis19837-Oct-05 3:44 
GeneralRe: Version 2.0 of this function Pinmemberjayoscar26-Feb-06 20:31 
GeneralNice but..... PinmemberBlade200026-Apr-05 3:28 
GeneralInverted return PinmemberFernando Hunth12-Nov-04 7:09 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 21 Jul 2004
Article Copyright 2004 by GRMartin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid