如何在VB.NET中甚至退出FormClosed [英] How to Exit even FormClosed in VB.NET
本文介绍了如何在VB.NET中甚至退出FormClosed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表单,并且我向事件FormClosed编写了代码.
在这种情况下,我会显示一条问题消息.如果用户选择否",则此表单未关闭,否则关闭表单.
但我不愿意,请帮忙吗?
谢谢,
I have a form and I wrote code to event FormClosed.
in this event I display a question message.If user choose No, this form is not closed else close form.
but i do not handle if, so could help me, please?
thanks,
推荐答案
而不是处理FormClosed,而是处理FormClosing:
Instead of handling FormClosed, handle FormClosing:
private void myForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Are you sure", "Close form", MessageBoxButtons.YesNo) != DialogResult.Yes)
{
e.Cancel = true;
}
}
糟糕!抱歉-我忘了你是VB:-O:
Oops! Sorry - I forgot you are VB :-O :
Private Sub myForm_FormClosing(sender As Object, e As FormClosingEventArgs)
If MessageBox.Show("Are you sure", "Close form", MessageBoxButtons.YesNo) <> DialogResult.Yes Then
e.Cancel = True
End If
End Sub
[edit]添加了VB版本的代码-OriginalGriff [/edit]
[edit]Added VB version of code - OriginalGriff[/edit]
处理表单关闭事件,并在其中显示消息框,提示用户是否单击了make
handle form closing event and show messagebox there with your question if user clicks no make
e.Cancel=true;
,这将阻止表单关闭
除了格里夫的正确答案:您还应该检查事件参数的ClosingReason
并取消仅针对ClosingReason.UserClosing
的表单关闭.
—SA
In addition to correct answer by Griff: you should check up event argument''sClosingReason
and cancel form closing only forClosingReason.UserClosing
.
—SA
这篇关于如何在VB.NET中甚至退出FormClosed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文