主窗体Form1
弹窗窗体Form2
在主窗体Form1的Button点击事件中加入:
private void btnXXX_Click(object sender, EventArgs e) { if (Form2.Instance == null || Form2.Instance.IsDisposed) { Form2 frm = new Form2(); Form2.Instance.Show(); } else { Form2.Instance.Activate(); } }
在弹窗窗体Form2中加入:
private static Form2 _instance = null; public static Form2 Instance { get { return _instance; } } public Form2() { InitializeComponent(); _instance = this; } private void Form2_FormClosed(object sender, FormClosedEventArgs e) { _instance = null; this.Dispose(); }