Click here to Skip to main content
11,935,053 members (56,279 online)
Click here to Skip to main content
Add your own
alternative version


20 bookmarked

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

, 20 Jul 2004 Public Domain
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.


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.


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;


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);


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.


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


About the Author

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.

You may also be interested in...

Comments and Discussions

GeneralAvoid to open more than one windows. Pin
V K Gupta26-May-09 0:11
memberV K Gupta26-May-09 0:11 
QuestionActive form Pin
thachvv1813-Jul-07 4:48
memberthachvv1813-Jul-07 4:48 
AnswerRe: Active form Pin
Giorgi Dalakishvili13-Jul-07 5:22
memberGiorgi Dalakishvili13-Jul-07 5:22 
GeneralRe: Active form Pin
gaurav_pandya29-Jul-08 20:35
membergaurav_pandya29-Jul-08 20:35 
GeneralGood Pin
davarmanesh12-Jun-07 7:28
memberdavarmanesh12-Jun-07 7:28 
Generalhelp... Pin
Gustavo Ushijima4-Mar-07 4:00
memberGustavo Ushijima4-Mar-07 4:00 
QuestionUsing MDI Form Pin
m3n5428-Sep-06 1:52
memberm3n5428-Sep-06 1:52 
AnswerRe: Using MDI Form Pin
hhmiles214-Jan-07 18:38
memberhhmiles214-Jan-07 18:38 
GeneralRe: Using MDI Form Pin
Gulkit Jain17-Nov-07 4:24
memberGulkit Jain17-Nov-07 4:24 
Questionaccess parent form of showgialog window Pin
amilapradeep25-Sep-06 3:42
memberamilapradeep25-Sep-06 3:42 
AnswerRe: access parent form of showgialog window Pin
amilapradeep25-Sep-06 4:32
memberamilapradeep25-Sep-06 4:32 
GeneralVersion 2.0 of this function Pin
javiersolis19837-Oct-05 4:44
memberjaviersolis19837-Oct-05 4:44 
GeneralRe: Version 2.0 of this function Pin
jayoscar26-Feb-06 21:31
memberjayoscar26-Feb-06 21:31 
GeneralNice but..... Pin
Blade200026-Apr-05 4:28
memberBlade200026-Apr-05 4:28 
GeneralInverted return Pin
Fernando Hunth12-Nov-04 8:09
memberFernando Hunth12-Nov-04 8:09 

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.

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