通过反射带调用窗体(转载)
通过Activator反射调用窗体,但是这个例子是要知道一个窗体的类才行。
因此只是反射调出窗体,不是“”
1 public static void OpenOneForm<T>(object[] parameters) where T : Form 2 { 3 Form openForm = null; 4 foreach (Form form in System.Windows.Forms.Application.OpenForms) 5 { 6 if (form.GetType() == typeof(T)) 7 { 8 openForm = form; 9 break; 10 } 11 } 12 if (openForm != null) 13 { 14 if (openForm.WindowState == FormWindowState.Minimized) 15 openForm.WindowState = FormWindowState.Normal; 16 openForm.Activate(); 17 } 18 else 19 { 20 openForm = (T)Activator.CreateInstance(typeof(T), parameters); 21 openForm.Show(); 22 } 23 }
源码出处CSND论坛:
http://bbs.csdn.net/topics/390361800