I have a form that is showing a MessageBox using MessageBox.Show, and trying to receive events from the Help button on the MessageBox so I can execute my own code. The Microsoft documentation shows how to do this; however, using what is suggested does not work. Here’s a shortened version of my code:
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
I’ve been searching for a solution to this problem, but the best I’ve found is this question: How to detect Help button press in Windows Forms MessageBox? that refers me back to the same Microsoft code that doesn’t seem to be working.
Can anybody help me with this?
Thank you.
As it turns out, there was another window Active than the Form calling the MessageBox. Since no version of MessageBox.Show allows you to both handle the HelpRequested event AND specify the Owner, MessageBox was looking to the ActiveForm for the recipient of the Event, rather than sending it to my Form. Making the following change finally got it working:
There are still a number of things that I will be fixing with this code relating to other things, but it sure is nice to finally have this figured out.
Thank you to everybody that helped.