我在想如何正確地在按鈕單擊事件之間切換窗體。在窗體之間切換並正確發送變量
我有Form1和Form2。 Form1中有:-TextBoxForm1 -ButtonForm1 Form2的有:-TextBoxForm2 -ButtonForm2
我想on_click ButtonForm1事件轉到窗體2。然後我想寫一些消息給TextBoxForm2並按下ButtonForm2它將再次進入Form1,TextBoxForm2中的消息將出現在TextBoxForm1中。
一切工作正常,但我有一個問題。當我關閉應用程序,我想調試並再次啓動時,出現一些錯誤:「應用程序已經在運行」。
Form1中:
public static string MSG;
public Form1()
{
InitializeComponent();
TextBoxForm1.Text = MSG;
}
private void ButtonForm1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
this.Hide();
//There is probably my fault but when I was trying this.Close(); everything shutted down
form2.Show();
}
窗體2:
private void ButtonForm2_Click(object sender, EventArgs e)
{
Form1.MSG = TextBoxForm2.Text;
Form1 form= new Form1();
form.Show();
this.Close();
}
我怎麼能這樣做正確嗎? :)我是初學者,謝謝!
爲form2的FormClosing事件編寫一個事件處理函數。這告訴你需要使主窗口再次可見。 – 2014-12-01 15:43:59