public partial class MainForm
{
private Dictionary<Type, Form> SingleInstanceForms = new Dictionary<Type, Form>();
protected Form ActivateForm<T>() where T : Form, new()
{
if (!this.SingleInstanceForms.ContainsKey(typeof(T)))
{
T newForm = new T();
// Set up the necessary properties
newForm.MdiParent = this;
newForm.FormClosed += new FormClosedEventHandler(delegate(object sender, FormClosedEventArgs e)
{
this.SingleInstanceForms.Remove(sender.GetType());
});
this.SingleInstanceForms.Add(typeof(T), newForm);
}
Form formToActivate = this.SingleInstanceForms[typeof(T)];
formToActivate.Show();
formToActivate.Activate();
return formToActivate;
}
//调用方法
this.ActivateForm<ChildForms.XXForm>(); //类
}