c#在vs2005如何实现关闭窗口事件(closing事件)

2024-12-20 20:05:30
推荐回答(1个)
回答1:

您好,

在C#中,窗口关闭的事件是FormClosing而不是Closing,因此您需要这样的代码:

private void button1_Click(object sender, EventArgs e)
{
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
}

void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Are you sure?","Application",MessageBoxButtons.YesNo,MessageBoxIcon.Information)==DialogResult.No)
{
e.Cancel = true;
}
}

希望对您有帮助。