private void Form1_FormClosing(object sender, FormClosingEventArgs e) { DialogResult re = MessageBox.Show("確定離開嗎","詢問",MessageBoxButtons.YesNo,Message ...
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { DialogResult re = MessageBox.Show("確定離開嗎","詢問",MessageBoxButtons.YesNo,MessageBoxIcon.Question); if(re==DialogResult.No) { e.Cancel = true; } } private void button1_Click(object sender, EventArgs e) { this.Close(); //點擊該button後實現關閉視窗 } private void button2_Click(object sender, EventArgs e) { Form2 frm = new Form2(); frm.ShowDialog(); //showdialog 模態出來的窗體如果想關閉主窗體 就必須先關閉模態窗體 //frm.Show();// show 可以再次點擊主視窗來打開無數個視窗 而不會強制停留在新視窗 }