Click here to Skip to main content
13,090,730 members (44,085 online)
Click here to Skip to main content
Add your own
alternative version


20 bookmarked
Posted 20 Jul 2004

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.


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 Gupta25-May-09 23:11
memberV K Gupta25-May-09 23:11 
Generalmultiple child pages Pin
kanza azhar13-Aug-08 6:00
memberkanza azhar13-Aug-08 6:00 
QuestionActive form Pin
thachvv1813-Jul-07 3:48
memberthachvv1813-Jul-07 3:48 
AnswerRe: Active form Pin
Giorgi Dalakishvili13-Jul-07 4:22
memberGiorgi Dalakishvili13-Jul-07 4:22 
GeneralRe: Active form Pin
gaurav_pandya29-Jul-08 19:35
membergaurav_pandya29-Jul-08 19:35 
GeneralGood Pin
davarmanesh12-Jun-07 6:28
memberdavarmanesh12-Jun-07 6:28 
Generalhelp... Pin
Gustavo Ushijima4-Mar-07 3:00
memberGustavo Ushijima4-Mar-07 3:00 
QuestionUsing MDI Form Pin
m3n5428-Sep-06 0:52
memberm3n5428-Sep-06 0:52 
AnswerRe: Using MDI Form Pin
hhmiles214-Jan-07 17:38
memberhhmiles214-Jan-07 17:38 
GeneralRe: Using MDI Form Pin
Gulkit Jain17-Nov-07 3:24
memberGulkit Jain17-Nov-07 3:24 
Questionaccess parent form of showgialog window Pin
amilapradeep25-Sep-06 2:42
memberamilapradeep25-Sep-06 2:42 
AnswerRe: access parent form of showgialog window Pin
amilapradeep25-Sep-06 3:32
memberamilapradeep25-Sep-06 3:32 
GeneralVersion 2.0 of this function Pin
javiersolis19837-Oct-05 3:44
memberjaviersolis19837-Oct-05 3:44 
GeneralRe: Version 2.0 of this function Pin
jayoscar26-Feb-06 20:31
memberjayoscar26-Feb-06 20:31 
GeneralNice but..... Pin
Blade200026-Apr-05 3:28
memberBlade200026-Apr-05 3:28 
GeneralInverted return Pin
Fernando Hunth12-Nov-04 7:09
memberFernando Hunth12-Nov-04 7: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170813.1 | Last Updated 21 Jul 2004
Article Copyright 2004 by GRMartin
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid