使用泛型,動態建立視窗 method<T>(T form)where T: Form, new()…
public partial class fmMain : Form
{
private static fmLogin _fmlogin = null;
public fmMain()
{
InitializeComponent();
}
private void 登入ToolStripMenuItem_Click(object sender, EventArgs e)
{
createForm<fmLogin>(_fmlogin);
}
//動態建立視窗
private void createForm<T>(T form)where T : Form, new(){
if (form != null) form.Dispose();
form = new T();
form.Disposed += delegate
{
form.Dispose();
form = null;
};
form.MdiParent = this;
form.Show();
}
}