/************************************************************
* 反射方法来处理每个子窗体只保留一个实例
* 调用方法,打开一个MDI子窗口
* OpenWindow(typeof(子窗口).ToString(), string(子窗口标题);
/*************************************************************/
/// <summary>
/// 打开子窗口
/// </summary>
/// <param name="ChildTypeString">子窗口Type</param>
/// <param name="FormText">子窗口标题</param>
private void OpenWindow(string ChildTypeString, string FormText)
{
Form myChild = null;
if (!ContainMDIChild(ChildTypeString))
{
// 获取当前进程的集合
Assembly assembly = Assembly.GetExecutingAssembly();
// 创建数据类型使用类型字符串
Type typForm = assembly.GetType(ChildTypeString);
// 创建对象使用类型的"InvokeMember"方法
Object obj = typForm.InvokeMember(
null,
BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance,
null,
null,
null);
// 显示子窗口
if (obj != null)
{
myChild = obj as Form;
myChild.MdiParent = this;
myChild.StartPosition = FormStartPosition.CenterScreen;
myChild.Text = FormText;
myChild.Show();
myChild.WindowState = FormWindowState.Normal;
myChild.Focus();
}
}
}