关于表格关闭事件我很困惑
我想要这样,当单击“x”按钮时,会出现一个消息框,显示“您确定要退出吗?”然后,如果“是”,则关闭,如果“否”,则保持打开状态。所以我的代码是:
Dim a As Integer
a = MessageBox.Show("Are you sure you want to exit?", _
"Vice Versa 1.0", _
MessageBoxButtons.YesNo, _
MessageBoxIcon.Information)
If a = vbYes Then
Me.Close()
Else
Exit Sub
End If
这应该有效,不是吗?当我调试我的项目时,单击“否”仍然会退出我的程序。这只是因为它处于调试模式还是我在这里遗漏了一些东西?
(编辑:)也没有警告或错误。
有没有办法让我的游戏在消息框显示时暂停?只有当用户按键盘上的“p”时,我才可以使用它。但也希望游戏在消息框显示时暂停,而不按“p”
I want it so when the "x" button is clicked a message box will appear saying "Are you sure you want to exit?" then if "yes" it closes and if "NO" it stays open. so my code is:
Dim a As Integer
a = MessageBox.Show("Are you sure you want to exit?", _
"Vice Versa 1.0", _
MessageBoxButtons.YesNo, _
MessageBoxIcon.Information)
If a = vbYes Then
Me.Close()
Else
Exit Sub
End If
This should work, no? When i debug my project clicking "no" still exits my program. Is this just because it's in debug mode or am i missing something here?
(EDIT:) Also no warnings or errors.
Is there a way i can make my game pause when the message box shows? I only have it working to if the users presses "p" on keyboard. But also want game paused when message box shows, without pressing "p"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还必须设置 Cancel 属性来取消关闭。在
Exit Sub
之前的行中添加:,您不必再次执行 Me.Close。编写 If 块的更好方法就是:
You also have to set the Cancel property to cancel the close. On the line before
Exit Sub
, add:and you don't have to do the Me.Close again. A better way to write your If block would simply be to have: