MessageBox.Show not raising HelpRequested event
-
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.MsgBoxHelpRequestedEnd Function
'
'
Private Sub MsgBoxHelpRequested(ByVal sender As Object, _
ByVal hlpevent As System.Windows.Forms.HelpEventArgs)
' Breakpoint that never gets hit
' More code
End SubI posted this question yesterday on stackoverflow[^], where we get into quite a spirited discussion, with a bunch of suggestions that ultimately never seemed to pan out, if you want to see what I've already tried. Currently I'm working on seeing if there's any way to determine if the event was even raised in the first place - either by trying to manually raise the event and see if my code gets called, or seeing if there's any way to break on an event. Does anybody have any suggestions? Oh, and by the way, Chris Maunder: CodeProject is much better designed than StackOverflow. Reading stackoverflow is a pain on the eyes, trying to comment is a pain in the neck - coming back home here is such a relief. While the people over there are just as nice as here, I wish I had thought to check here yesterday.
-
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.MsgBoxHelpRequestedEnd Function
'
'
Private Sub MsgBoxHelpRequested(ByVal sender As Object, _
ByVal hlpevent As System.Windows.Forms.HelpEventArgs)
' Breakpoint that never gets hit
' More code
End SubI posted this question yesterday on stackoverflow[^], where we get into quite a spirited discussion, with a bunch of suggestions that ultimately never seemed to pan out, if you want to see what I've already tried. Currently I'm working on seeing if there's any way to determine if the event was even raised in the first place - either by trying to manually raise the event and see if my code gets called, or seeing if there's any way to break on an event. Does anybody have any suggestions? Oh, and by the way, Chris Maunder: CodeProject is much better designed than StackOverflow. Reading stackoverflow is a pain on the eyes, trying to comment is a pain in the neck - coming back home here is such a relief. While the people over there are just as nice as here, I wish I had thought to check here yesterday.
Yes i have a suggestion; I placed a button on the form, and coded the following;
Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim response As MsgBoxResult = MsgBox("the prompt", MsgBoxStyle.MsgBoxHelp + MsgBoxStyle.Information + MsgBoxStyle.YesNo, "The Title") MsgBox(response) End Sub Private Sub FormMain\_HelpRequested(ByVal sender As Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles Me.HelpRequested MsgBox("help Requested") End Sub
This displays a Yes No Help msgbox, when the help is pressed, another msgbox appears with the help requested. Based on this, what you could do is set a variable before entering the msgbox with some form of identifier, then in the HelpRequested call, check the value of that variable and perform the appropriate help action.
Dave Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn
Waving? dave.m.auld[at]googlewave.com -
Yes i have a suggestion; I placed a button on the form, and coded the following;
Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim response As MsgBoxResult = MsgBox("the prompt", MsgBoxStyle.MsgBoxHelp + MsgBoxStyle.Information + MsgBoxStyle.YesNo, "The Title") MsgBox(response) End Sub Private Sub FormMain\_HelpRequested(ByVal sender As Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles Me.HelpRequested MsgBox("help Requested") End Sub
This displays a Yes No Help msgbox, when the help is pressed, another msgbox appears with the help requested. Based on this, what you could do is set a variable before entering the msgbox with some form of identifier, then in the HelpRequested call, check the value of that variable and perform the appropriate help action.
Dave Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn
Waving? dave.m.auld[at]googlewave.comOkay, I'm not sure why you're showing a second MsgBox to display the MsgBoxResult of the first one in the first function, but the second function doesn't help me because it's yet another variation of what I've been trying to do that I have already determined does not work for me.
-
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.MsgBoxHelpRequestedEnd Function
'
'
Private Sub MsgBoxHelpRequested(ByVal sender As Object, _
ByVal hlpevent As System.Windows.Forms.HelpEventArgs)
' Breakpoint that never gets hit
' More code
End SubI posted this question yesterday on stackoverflow[^], where we get into quite a spirited discussion, with a bunch of suggestions that ultimately never seemed to pan out, if you want to see what I've already tried. Currently I'm working on seeing if there's any way to determine if the event was even raised in the first place - either by trying to manually raise the event and see if my code gets called, or seeing if there's any way to break on an event. Does anybody have any suggestions? Oh, and by the way, Chris Maunder: CodeProject is much better designed than StackOverflow. Reading stackoverflow is a pain on the eyes, trying to comment is a pain in the neck - coming back home here is such a relief. While the people over there are just as nice as here, I wish I had thought to check here yesterday.
So, I'm not sure what's wrong with your code. I did this:
Private Sub Button3_Click(...)
AddHandler Me.HelpRequested, AddressOf Me.MsgBoxHelpRequestedSelect Case MessageBox.Show("Text","Title", MessageBoxButtons.YesNoCancel, _
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, 0, True)End Select
End SubPrivate Sub MsgBoxHelpRequested(...)
MessageBox.Show("got here")
End Suband I "got here". Am I the only one that this works for?
-
Okay, I'm not sure why you're showing a second MsgBox to display the MsgBoxResult of the first one in the first function, but the second function doesn't help me because it's yet another variation of what I've been trying to do that I have already determined does not work for me.
i was only using msgbox to illustrate a point thats all. What are you trying to do then, what i have shown in the example code is the help button being handled, which is what i thought you couldn't achieve?
Private helpTopic as integer =0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
helpTopic = 1 Dim response As MsgBoxResult = MsgBox("the prompt", MsgBoxStyle.MsgBoxHelp + MsgBoxStyle.Information + MsgBoxStyle.YesNo, "The Title") If response = vbYes Then 'User Selects Yes Else 'Do something else if anything End If End Sub Private Sub FormMain\_HelpRequested(ByVal sender As Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles Me.HelpRequested Select Case helpTopic Case 1 'User want help with topic 1 Case Else 'User called help for something else End Select End Sub
is that better without the extra msgboxes!
Dave Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn
Waving? dave.m.auld[at]googlewave.com -
So, I'm not sure what's wrong with your code. I did this:
Private Sub Button3_Click(...)
AddHandler Me.HelpRequested, AddressOf Me.MsgBoxHelpRequestedSelect Case MessageBox.Show("Text","Title", MessageBoxButtons.YesNoCancel, _
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, 0, True)End Select
End SubPrivate Sub MsgBoxHelpRequested(...)
MessageBox.Show("got here")
End Suband I "got here". Am I the only one that this works for?
Actually, I seem to be the only one it doesn't work for. And only in this project. I've copied and pasted my exact code to a new Project, and after taking care of all the blue underlines, it works perfectly. I can't figure out why it's not working in the the real application; the only thing I can think is that the event is never being fired from the MessageBox somehow - I've added handlers for the event in every possible way I can think of, and none of them ever get called. If only I could fire the event myself or break execution when the event is called, it would be so tremendously helpful, but I neither of these seem possible, and I'm getting extremely frustrated.
-
So, I'm not sure what's wrong with your code. I did this:
Private Sub Button3_Click(...)
AddHandler Me.HelpRequested, AddressOf Me.MsgBoxHelpRequestedSelect Case MessageBox.Show("Text","Title", MessageBoxButtons.YesNoCancel, _
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, 0, True)End Select
End SubPrivate Sub MsgBoxHelpRequested(...)
MessageBox.Show("got here")
End Suband I "got here". Am I the only one that this works for?
Nope, that works for me also. Both Versions of Code, using 2 buttons on form;
Public Class FormMain
Private helpTopic As Integer = 0 Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click helpTopic = 1 Dim response As MsgBoxResult = MsgBox("the prompt", MsgBoxStyle.MsgBoxHelp + MsgBoxStyle.Information + MsgBoxStyle.YesNo, "The Title") If response = vbYes Then 'User Selects Yes Else 'Do something else if anything End If End Sub Private Sub FormMain\_HelpRequested(ByVal sender As Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles Me.HelpRequested Select Case helpTopic Case 1 'User want help with topic 1 Case Else 'User called help for something else End Select End Sub Private Sub Button2\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click AddHandler Me.HelpRequested, AddressOf Button2Help MessageBox.Show("The text", "The caption", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0, True) End Sub Private Sub Button2Help() MsgBox("Some help please") End Sub
End Class
Dave Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn
Waving? dave.m.auld[at]googlewave.com -
i was only using msgbox to illustrate a point thats all. What are you trying to do then, what i have shown in the example code is the help button being handled, which is what i thought you couldn't achieve?
Private helpTopic as integer =0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
helpTopic = 1 Dim response As MsgBoxResult = MsgBox("the prompt", MsgBoxStyle.MsgBoxHelp + MsgBoxStyle.Information + MsgBoxStyle.YesNo, "The Title") If response = vbYes Then 'User Selects Yes Else 'Do something else if anything End If End Sub Private Sub FormMain\_HelpRequested(ByVal sender As Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles Me.HelpRequested Select Case helpTopic Case 1 'User want help with topic 1 Case Else 'User called help for something else End Select End Sub
is that better without the extra msgboxes!
Dave Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn
Waving? dave.m.auld[at]googlewave.com -
Actually, I seem to be the only one it doesn't work for. And only in this project. I've copied and pasted my exact code to a new Project, and after taking care of all the blue underlines, it works perfectly. I can't figure out why it's not working in the the real application; the only thing I can think is that the event is never being fired from the MessageBox somehow - I've added handlers for the event in every possible way I can think of, and none of them ever get called. If only I could fire the event myself or break execution when the event is called, it would be so tremendously helpful, but I neither of these seem possible, and I'm getting extremely frustrated.
check you haven't got 2 handlers poitint to the same code, that seems to effect things. For example, look at my most recent code i have the Button2Help, if i change the handler to FormMain_HelpRequested (which is handled by Me.HelpRequested) it won't work.
Dave Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn
Waving? dave.m.auld[at]googlewave.com -
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.MsgBoxHelpRequestedEnd Function
'
'
Private Sub MsgBoxHelpRequested(ByVal sender As Object, _
ByVal hlpevent As System.Windows.Forms.HelpEventArgs)
' Breakpoint that never gets hit
' More code
End SubI posted this question yesterday on stackoverflow[^], where we get into quite a spirited discussion, with a bunch of suggestions that ultimately never seemed to pan out, if you want to see what I've already tried. Currently I'm working on seeing if there's any way to determine if the event was even raised in the first place - either by trying to manually raise the event and see if my code gets called, or seeing if there's any way to break on an event. Does anybody have any suggestions? Oh, and by the way, Chris Maunder: CodeProject is much better designed than StackOverflow. Reading stackoverflow is a pain on the eyes, trying to comment is a pain in the neck - coming back home here is such a relief. While the people over there are just as nice as here, I wish I had thought to check here yesterday.
This code is actually getting executed by way of a .dll which Raises an event back on the calling Form that leads to this code. If I move this code back to just before where the code heads out to the .dll, it works. Could something be going on behind the scenes due to the .dll call that could be causing this?
modified on Thursday, May 13, 2010 4:58 PM
-
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.MsgBoxHelpRequestedEnd Function
'
'
Private Sub MsgBoxHelpRequested(ByVal sender As Object, _
ByVal hlpevent As System.Windows.Forms.HelpEventArgs)
' Breakpoint that never gets hit
' More code
End SubI posted this question yesterday on stackoverflow[^], where we get into quite a spirited discussion, with a bunch of suggestions that ultimately never seemed to pan out, if you want to see what I've already tried. Currently I'm working on seeing if there's any way to determine if the event was even raised in the first place - either by trying to manually raise the event and see if my code gets called, or seeing if there's any way to break on an event. Does anybody have any suggestions? Oh, and by the way, Chris Maunder: CodeProject is much better designed than StackOverflow. Reading stackoverflow is a pain on the eyes, trying to comment is a pain in the neck - coming back home here is such a relief. While the people over there are just as nice as here, I wish I had thought to check here yesterday.
OH. MY. GOODNESS. So I started checking the source code for the MessageBox.Show in Reflector. As it turns out, if you don't specify the Owner, as you aren't allowed to do when you want to handle HelpRequested yourself, it uses UnsafeNativeMethods.GetActiveWindow() to determine who to send the HelpRequested to. The moment I saw this, I knew what was going on. The application I'm working in has a splash screen that shows the status to the user that is shown in the .dll. THAT is the ActiveWindow. When I forced it down and called Activate on my Form just before this code, it worked.
Trevortni wrote:
Private Function MethodName() As Boolean
Me.Activate()
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 finally gets hit
' More code
End Sub -
OH. MY. GOODNESS. So I started checking the source code for the MessageBox.Show in Reflector. As it turns out, if you don't specify the Owner, as you aren't allowed to do when you want to handle HelpRequested yourself, it uses UnsafeNativeMethods.GetActiveWindow() to determine who to send the HelpRequested to. The moment I saw this, I knew what was going on. The application I'm working in has a splash screen that shows the status to the user that is shown in the .dll. THAT is the ActiveWindow. When I forced it down and called Activate on my Form just before this code, it worked.
Trevortni wrote:
Private Function MethodName() As Boolean
Me.Activate()
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 finally gets hit
' More code
End Sub -
OH. MY. GOODNESS. So I started checking the source code for the MessageBox.Show in Reflector. As it turns out, if you don't specify the Owner, as you aren't allowed to do when you want to handle HelpRequested yourself, it uses UnsafeNativeMethods.GetActiveWindow() to determine who to send the HelpRequested to. The moment I saw this, I knew what was going on. The application I'm working in has a splash screen that shows the status to the user that is shown in the .dll. THAT is the ActiveWindow. When I forced it down and called Activate on my Form just before this code, it worked.
Trevortni wrote:
Private Function MethodName() As Boolean
Me.Activate()
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 finally gets hit
' More code
End SubKudos to you for posting the solution.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”