Check to see if an MDI Child is already active in an MDI Parent - The Code Project - C# Programming:
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();
}
0 Comments:
Post a Comment
<< Home