您好,
在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;
}
}
希望对您有帮助。