► for class
► for name
//use findForm(typeof(ContainerInEditForm) public static Boolean findForm(Type FormType) { foreach (Form form in Application.OpenForms) { if (form.GetType() == FormType) { form.WindowState = FormWindowState.Normal; form.Show(); form.BringToFront(); form.Activate(); return false; } } return true; }
► for name
► 建立實例//use findForm("ContainerInEditForm") <= Form.name public static Boolean findForm(string formName) { Form form = Application.OpenForms[formName]; if (form != null) { form.WindowState = FormWindowState.Normal; form.Show(); form.BringToFront(); form.Activate(); return false; } else return true; }
public static T CreateInstance<T>() where T : new() { // Do some business logic return new T(); }