在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
}
}
希望对您有帮助销誉。
你可以加入下面的代枣山码:private void button1_Click(object sender, EventArgs e)
{
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing)
}
void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("你确定关闭窗口吗?","册世Application",MessageBoxButtons.YesNo,MessageBoxIcon.Information)==DialogResult.No)
{
e.Cancel = true
}
}
希望对您州岩肢有帮助。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)