關閉視窗→Close Event →MessageBox Yes / No
關閉視窗→Close Event →MessageBox Yes / No
- Yes 關閉
- No 不關閉
private void Form1_Load(object sender, EventArgs e)
{
this.FormClosing += new FormClosingEventHandler(Close_Event_MessageBox);
}
private void Close_Event_MessageBox(object sender, CancelEventArgs e)
{
if (MessageBox.Show("是否要關閉程式?", "關閉程式", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
e.Cancel = false;
}
else
{
e.Cancel = true;
}
}