vb.net - MessageBox.Show 不引发 HelpRequested 事件

标签 vb.net winforms events msgbox

我有一个使用 MessageBox.Show 显示 MessageBox 的表单,并尝试从 MessageBox 上的“帮助”按钮接收事件,以便我可以执行自己的代码。 Microsoft 文档显示了如何执行此操作;但是,使用建议的内容不起作用。这是我的代码的简化版本:

    Private Function MethodName() As Boolean

      AddHandler Me.HelpRequested, AddressOf Me.MsgBoxHelpRequested
      Select Case MessageBox.Show("Text", "Title", MessageButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, 0, True)
        Case MsgBoxResult.Yes
          ' Do stuff
        Case MsgBoxResult.No
          ' Do stuff
        Case MsgBoxResult.Cancel
          RemoveHandler Me.HelpRequested, AddressOf Me.MsgBoxHelpRequested
          Return False
      End Select
      RemoveHandler Me.HelpRequested, AddressOf Me.MsgBoxHelpRequested

    End Function

Private Sub MsgBoxHelpRequested(ByVal sender As Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs)
  ' Breakpoint that never gets hit
  ' More code
End Sub

我一直在寻找这个问题的解决方案,但我找到的最好的解决方案是这个问题:How to detect Help button press in Windows Forms MessageBox?这让我回到了似乎不起作用的相同 Microsoft 代码。

谁能帮我解决这个问题?

谢谢。

最佳答案

Me 作为第一个参数传递给 MessageBox.Show

将处理程序添加到 Form.ActiveForm 而不是 Me

关于vb.net - MessageBox.Show 不引发 HelpRequested 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2822805/

相关文章:

jquery 函数在事件内部运行一次

javascript - Backbone.Collection 触发 'reset' 但不是 'add'

vb.net 检测Web浏览器控件中的链接是否被单击

javascript - 在后面的代码中获取确认值

c# - VB.net 的 InputDialog 的 C# 版本是什么?

c# - 如何在我的 C# 应用程序中显示任务栏通知?

c# - 使用 DataGridViewImageColumn 将图像添加到 DataGridView

ios - 如何在 IOS 中通过预定义的短语和盐值生成散列键?

c# - 在运行时构建控件

jquery - Cordova iOS onResume 在启动时触发并导致应用程序崩溃