日期:2014-05-18 浏览次数:20757 次
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void showForm<T>(params object[] args) where T:Form { Form form = null; IEnumerable<T> forms = Application.OpenForms.OfType<T>(); if (forms.Any()) form = forms.First(); if (form == null) form =(Form) Activator.CreateInstance(typeof(T), args); if (form.WindowState == FormWindowState.Minimized) form.WindowState = FormWindowState.Normal; else form.Show(); } private void button1_Click(object sender, EventArgs e) { this.showForm<Form2>(); } }