VB.NET:中止 FormClosing()
我有一个代码片段,我想在应用程序关闭时运行。因此,我使用了 FormCLosing
事件。但现在我想放置一条退出确认消息。例如,如果用户单击“退出”(X
) 按钮,则会出现提示,如果单击“否”,则应用程序不会关闭并恢复到之前的状态。
现在我发现使用 FormClosing
事件很难实现。因为无论用户单击哪个按钮它都会被执行。 有什么补救办法吗?
我的意思是,我需要一个像 ExitButtonPressed()
..
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.
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?
I mean, I need an even like ExitButtonPressed()
..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试
查看
FormClosingEventArgs Class
和
CancelEventArgs.Cancel 属性
You could try something like
Have a look at
FormClosingEventArgs Class
And
CancelEventArgs.Cancel Property
'表单的 Button2 和 closebutton 都关闭表单,询问相同的'问题
Dim button2Yes As Boolean = False
Private Sub Button2_Click(sender As Object, e As EventArgs) 处理 Button2.Click
'Button2 and closebutton of the form both closes the form asking the same 'question
Dim button2Yes As Boolean = False
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click