这是我在MDI父窗体的代码: public partial class Manager : Form
{
public Manager()
{
InitializeComponent();
}
MgEmployee mge;
// int flag;
private void 员工资料管理ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (mge == null || mge.IsDisposed)
{
mge = new MgEmployee();
mge.Show();
mge.MdiParent = this;
}
else
{
mge.WindowState = FormWindowState.Normal;
}
}由于有多个界面,所以if else这段代码就要写很多次,我想把它拿出来做成一个方法,但是不知道要怎么写,请大家指点。
{
public Manager()
{
InitializeComponent();
}
MgEmployee mge;
// int flag;
private void 员工资料管理ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (mge == null || mge.IsDisposed)
{
mge = new MgEmployee();
mge.Show();
mge.MdiParent = this;
}
else
{
mge.WindowState = FormWindowState.Normal;
}
}由于有多个界面,所以if else这段代码就要写很多次,我想把它拿出来做成一个方法,但是不知道要怎么写,请大家指点。
interface IForm
{
string Name{get;set}
Form Windows{get;set}
}interface IFactory
{
IForm createForm(string name)
IForm getForm(string name)
}pubilc class ChildForm : IForm{}public class ChildFormFactory : Ifactory
{
private List<IForm> mForms = new List<IForm>();
public IForm create(string name){
..create your form
}
}public class ClassTest{
private void 员工资料管理ToolStripMenuItem_Click(object sender, EventArgs e)
{
IForm child = ChildFormFactory.create("员工资料管理")
child.Form.parent = this;
}
}
你完全通过
<xml>
<Form name="你好" class="System.MyClass.Nihao" />
<Form name="你好2" class="System.MyClass.Nihao2" />
<Form name="你好3" class="System.MyClass.Nihao3" />
</xml>
通过反射机制读取
如果不是 一个要扩展的系统 3楼就可以了
{
int Children_Count=this.MdiChildren.Length;
for(int i=0;i<Children_Count;i++)
{
if(this.MdiChildren[i].WindowState==FormWindowState.Maximized )
this.MdiChildren[i].WindowState=FormWindowState.Normal;
}
}
private bool GetInstanceState(string Frm_Name)
{
this.State_Judge();
int Children_Count=this.MdiChildren.Length;
for(int i=0;i<Children_Count;i++)
{
if (this.MdiChildren[i].Name==Frm_Name )
{
this.MdiChildren[i].WindowState=System.Windows.Forms.FormWindowState.Normal;
this.MdiChildren[i].Focus();
return true;
}
}
return false;
}