MessageBox.Show不提升HelpRequested事件 [英] MessageBox.Show not raising HelpRequested event
问题描述
我有一个使用MessageBox.Show显示MessageBox的表单,并尝试从MessageBox上的帮助按钮接收事件,以便我可以执行我自己的代码。 Microsoft文档显示如何执行此操作;然而,使用建议不行。以下是我的代码的缩写版本:
私有函数MethodName()作为Boolean
AddHandler Me。 HelpRequested,AddressOf Me.MsgBoxHelpRequested
选择案例MessageBox.Show(Text,Title,MessageButtons.YesNoCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2,0,True)
Case MsgBoxResult.Yes
'做东西
案例MsgBoxResult.No
'做东西
案例MsgBoxResult.Cancel
RemoveHandler Me.HelpRequested,AddressOf Me.MsgBoxHelpRequested
返回False
结束选择
RemoveHandler Me.HelpRequested,AddressOf Me.MsgBoxHelpRequested
结束函数
私有子MsgBoxHelpRequested(ByVal sender As Object,ByVal hlpevent As System.Windows。 Forms.HelpEventArgs)
'从未得到的断点
'更多代码
End Sub
我一直在寻找注意这个问题,但我发现最好的是这个问题:如何检测Windows窗体MessageBox中的帮助按钮?,将我引回到似乎不起作用的相同的Microsoft代码。
<有人可以帮助我吗?
谢谢。
p>事实证明,还有另一个窗口Active,而不是调用MessageBox的窗体。由于没有任何版本的MessageBox.Show允许您同时处理HelpRequested事件 AND 指定所有者,MessageBox正在寻找活动的收件人的ActiveForm,而不是将其发送到我的窗体。进行以下更改终于有效:
私有函数MethodName()As Boolean
我。激活()'< ------------------- !!!!!!!!!
AddHandler Me.HelpRequested,AddressOf Me.MsgBoxHelpRequested
选择案例MessageBox.Show(Text,Title,MessageButtons.YesNoCancel,_
MessageBoxIcon.Question,MessageBoxDefaultButton。 Button2,0,True)
案例MsgBoxResult.Yes
'做东西
案例MsgBoxResult.No
'做东西
案例MsgBoxResult.Cancel
RemoveHandler我.HelpRequested,AddressOf Me.MsgBoxHelpRequested
返回False
结束选择
RemoveHandler Me.HelpRequested,AddressOf Me.MsgBoxHelpRequested
结束函数
Private Sub MsgBoxHelpRequested(ByVal sender As Object,_
ByVal hlpevent As System.Windows.Forms.HelpEventArgs)
'断点**最后**获得命中
'更多代码
End Sub
仍然有一些事情,我将使用与其他事情相关的代码来修复,但是肯定很好,终于有了这个想法
感谢所有帮助的人。
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:
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
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.
这篇关于MessageBox.Show不提升HelpRequested事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!