带有 YesNoCancel 的 MessageBox - No &取消触发相同的事件 [英] MessageBox with YesNoCancel - No & Cancel triggers same event
本文介绍了带有 YesNoCancel 的 MessageBox - No &取消触发相同的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有 YesNoCancel
按钮的消息框...
I have a message box with the YesNoCancel
buttons...
- 按
Yes
将执行一些操作并关闭应用程序 - 工作正常 - 按
No
不会做任何事情并关闭应用程序 -(见下文) - 按
Cancel
不会做任何事情,并保持应用程序打开 -(见下文).
- Pressing
Yes
will do some action and close the application - works fine - Pressing
No
will do nothing and close the application - (see below) - Pressing
Cancel
will do nothing and keep the application open - (see below).
我使用 DialogResult.No
作为 No 按钮和 DialogResult.Cancel
作为 Cancel 按钮.但是按下它们中的任何一个都会触发 DialogResult.Cancel
事件.有什么问题?
I'm using DialogResult.No
for the No button and DialogResult.Cancel
for the Cancel button. But pressing either of them triggers DialogResult.Cancel
event. What's the problem?
推荐答案
这应该可以正常工作:
Dim result As DialogResult = MessageBox.Show("message", "caption", MessageBoxButtons.YesNoCancel)
If result = DialogResult.Cancel Then
MessageBox.Show("Cancel pressed")
ElseIf result = DialogResult.No Then
MessageBox.Show("No pressed")
ElseIf result = DialogResult.Yes Then
MessageBox.Show("Yes pressed")
End If
这篇关于带有 YesNoCancel 的 MessageBox - No &取消触发相同的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文