Click here to Skip to main content
Licence 
First Posted 20 Jul 2004
Views 55,484
Bookmarked 16 times

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

By | 20 Jul 2004 | Article
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

GRMartin

Web Developer

United States United States

Member

Im currently living in Connecticut, working for a great company.
 
Currently im working with Macromedia Flash (ActionScript/Flash JavaScript), CSS, JS, PHP, MySQL, the Microsoft Jet Engine, C# 2003 and VB.net 2003.
 
I starting programming about 11 years ago playing with GW and Q(uick)BASIC. And have since never stopped.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralAvoid to open more than one windows. PinmemberV K Gupta23:11 25 May '09  
Generalmultiple child pages Pinmemberkanza azhar6:00 13 Aug '08  
QuestionActive form Pinmemberthachvv183:48 13 Jul '07  
AnswerRe: Active form PinmemberGiorgi Dalakishvili4:22 13 Jul '07  
GeneralRe: Active form Pinmembergaurav_pandya19:35 29 Jul '08  
GeneralGood Pinmemberdavarmanesh6:28 12 Jun '07  
Generalhelp... PinmemberGustavo Ushijima3:00 4 Mar '07  
QuestionUsing MDI Form Pinmemberm3n540:52 28 Sep '06  
AnswerRe: Using MDI Form Pinmemberhhmiles217:38 14 Jan '07  
GeneralRe: Using MDI Form PinmemberGulkit Jain3:24 17 Nov '07  
Questionaccess parent form of showgialog window Pinmemberamilapradeep2:42 25 Sep '06  
AnswerRe: access parent form of showgialog window Pinmemberamilapradeep3:32 25 Sep '06  
GeneralVersion 2.0 of this function Pinmemberjaviersolis19833:44 7 Oct '05  
GeneralRe: Version 2.0 of this function Pinmemberjayoscar20:31 26 Feb '06  
GeneralNice but..... PinmemberBlade20003:28 26 Apr '05  
GeneralInverted return PinmemberFernando Hunth7:09 12 Nov '04  

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.

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