VB.NET:中止FormClosing() [英] VB.NET: Abort FormClosing()
问题描述
我有一个要在应用程序关闭时运行的代码段.因此,我使用了FormCLosing
事件.但是,现在我想发出一条确认消息以退出.就像,如果用户单击Exit(X
)按钮,则会出现提示,如果他单击NO,则该应用程序将不会关闭并恢复到以前的状态.
I have a code snippet that I want to run when the app is closing. So, I used FormCLosing
event. But now i wanna place a confirmation message for exiting. Like, if the user clicks the Exit(X
) button, there'll be a prompt, if he clicks NO, then the app will not close and revert to previous state.
现在,我发现使用FormClosing
事件很难实现.因为无论用户单击什么按钮,它都会执行.
有什么补救办法吗?
Now I find that hard to achieve using FormClosing
event. because it'll get executed no matter what button the user clicks.
Any remedy for that?
我的意思是,我需要一个像ExitButtonPressed()
一样的东西.
I mean, I need an even like ExitButtonPressed()
..
推荐答案
您可以尝试类似
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If (MessageBox.Show("Close?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No) Then
e.Cancel = True
End If
End Sub
看看
还有
可以通过设置取消活动 将Cancel属性设置为true.
The event can be canceled by setting the Cancel property to true.
这篇关于VB.NET:中止FormClosing()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!