View Code
/// <summary>
///
/// </summary>
/// <param name="mdiParent"></param>
/// <param name="frmtype"></param>
/// <returns></returns>
public static bool IsExistInstance(System.Windows.Forms.Form mdiParent, System.Type frmtype)
{
System.Windows.Forms.Form[] f = null;
int i = 0;
f = mdiParent.MdiChildren;
for (i = 0; i <= f.Length - 1; i++)
{
if (f[i].GetType().Equals(frmtype))
{
return true;
}
}
return false;
}
/// <summary>
///
/// </summary>
/// <param name="mdiParent"></param>
/// <param name="midChild"></param>
/// <returns></returns>
public static bool IsExistInstance(System.Windows.Forms.Form mdiParent, Form midChild)
{
System.Windows.Forms.Form[] f = null;
int i = 0;
f = mdiParent.MdiChildren;
for (i = 0; i <= f.Length - 1; i++)
{
if (object.ReferenceEquals(f[i], midChild))
{
return true;
}
}
return false;
}
/// <summary>
///
/// </summary>
/// <param name="mdiParent"></param>
/// <param name="frmtype"></param>
/// <returns></returns>
public static Form GetFormInstance(System.Windows.Forms.Form mdiParent, System.Type frmtype)
{
System.Windows.Forms.Form[] f = null;
int i = 0;
f = mdiParent.MdiChildren;
for (i = 0; i <= f.Length - 1; i++)
{
if (f[i].GetType().Equals(frmtype))
{
return f[i];
}
}
return null;
}
/// <summary>
///
/// </summary>
/// <param name="mdiParent"></param>
/// <param name="midChild"></param>
/// <returns></returns>
public static Form GetFormInstance(System.Windows.Forms.Form mdiParent, Form midChild)
{
System.Windows.Forms.Form[] f = null;
int i = 0;
f = mdiParent.MdiChildren;
for (i = 0; i <= f.Length - 1; i++)
{
if (object.ReferenceEquals(f[i], midChild))
{
return f[i];
}
}
return null;
}
///
/// </summary>
/// <param name="mdiParent"></param>
/// <param name="frmtype"></param>
/// <returns></returns>
public static bool IsExistInstance(System.Windows.Forms.Form mdiParent, System.Type frmtype)
{
System.Windows.Forms.Form[] f = null;
int i = 0;
f = mdiParent.MdiChildren;
for (i = 0; i <= f.Length - 1; i++)
{
if (f[i].GetType().Equals(frmtype))
{
return true;
}
}
return false;
}
/// <summary>
///
/// </summary>
/// <param name="mdiParent"></param>
/// <param name="midChild"></param>
/// <returns></returns>
public static bool IsExistInstance(System.Windows.Forms.Form mdiParent, Form midChild)
{
System.Windows.Forms.Form[] f = null;
int i = 0;
f = mdiParent.MdiChildren;
for (i = 0; i <= f.Length - 1; i++)
{
if (object.ReferenceEquals(f[i], midChild))
{
return true;
}
}
return false;
}
/// <summary>
///
/// </summary>
/// <param name="mdiParent"></param>
/// <param name="frmtype"></param>
/// <returns></returns>
public static Form GetFormInstance(System.Windows.Forms.Form mdiParent, System.Type frmtype)
{
System.Windows.Forms.Form[] f = null;
int i = 0;
f = mdiParent.MdiChildren;
for (i = 0; i <= f.Length - 1; i++)
{
if (f[i].GetType().Equals(frmtype))
{
return f[i];
}
}
return null;
}
/// <summary>
///
/// </summary>
/// <param name="mdiParent"></param>
/// <param name="midChild"></param>
/// <returns></returns>
public static Form GetFormInstance(System.Windows.Forms.Form mdiParent, Form midChild)
{
System.Windows.Forms.Form[] f = null;
int i = 0;
f = mdiParent.MdiChildren;
for (i = 0; i <= f.Length - 1; i++)
{
if (object.ReferenceEquals(f[i], midChild))
{
return f[i];
}
}
return null;
}
调用:
//检查指定MDI窗体的实例是否存在。
IsExistInstance(this, typeof(WindowsFormsApplication2.Form1));
//或者
IsExistInstance(this, System.Type.GetType("WindowsFormsApplication2.Form1"));
/www.w3.org/1999/xhtml:sentencetext>//www.w3.org/1999/xhtml:sentencetext>http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=ZH-CN&k=k(SYSTEM.STRING.EQUALS);k(EQUALS)&rd=true
="http://www.w3.org/1999/xhtml">is 检查对象是否与指定类型。
来源:https://www.cnblogs.com/51net/archive/2013/05/12/3074345.html