MessageBox的使用YesNoCancel - 否放;取消触发同一事件 [英] MessageBox with YesNoCancel - No & Cancel triggers same event

查看:1819
本文介绍了MessageBox的使用YesNoCancel - 否放;取消触发同一事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与 YesNoCancel 按钮的消息框...

I have a message box with the YesNoCancel buttons...


  • pressing 会做一些动作和关闭应用程序 - 正常工作

  • pressing 会做什么并关闭应用程序 - (见下文)

  • pressing 取消会做什么,保持应用程序打开 - 。(见下文)

  • 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 为<大骨节病>否按钮和 DialogResult.Cancel 为<大骨节病>取消按钮。但是,pressing其中任何一个触发 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 Integer = 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

这篇关于MessageBox的使用YesNoCancel - 否放;取消触发同一事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆