那A Form就先隱藏起來,等到B Form關閉時會執行FormClosed事件,B Form的FormClosed事件是針對A Form視窗去使用的,所以就顯示出A Form視窗
A Form
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace ABtest { public partial class A : Form { public A() { InitializeComponent(); } private void button_Click(object sender, EventArgs e) { B bForm = new B(); bForm.FormClosed += new FormClosedEventHandler(B_FormClosed); bForm.Show(); this.Hide(); } private void B_FormClosed(object sender, FormClosedEventArgs e) { this.Show(); } } }
B Form
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace ABtest { public partial class B : Form { public B() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.Close(); } } }
參考資料:
http://createps.pixnet.net/blog/post/32345801