表单关闭事件处理程序 [英] Form Closing event handler
问题描述
嗨我有以下代码,其中winform会在关闭表单之前提示我一条消息。当我点击关闭按钮。 YesNo消息将要求我确认。当我单击是,它应该关闭,当不,它应该保持。但问题是无论我点击是或否,winform也会关闭。以下是我的代码。任何帮助将不胜感激。
<前lang =cs> 私人 void Form1_Closing( object sender,System.ComponentModel.CancelEventArgs e)
{
DialogResult confirm = MessageBox。显示( 确认退出应用程序?, 确认,MessageBoxButtons.YesNo);
if (confirm == DialogResult.Yes)
{
Application.Exit();
}
}
你应该使用e.Cancel = true;
forelse
branch。
hi i have the following codes in which the winform will prompt me a message before closing the form. When i click the close button. A YesNo message will ask me for confirmation. When i click Yes, it should close and when No, it should remain. But the problem is no matter i click Yes or No, the winform will also close. Below are my codes. Any help would be appreciated.
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
DialogResult confirm = MessageBox.Show("Confirm Exit the application ?", "Confirmation", MessageBoxButtons.YesNo);
if (confirm == DialogResult.Yes)
{
Application.Exit();
}
}
You should usee.Cancel = true;
forelse
branch.
这篇关于表单关闭事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!