验证事件中的MessageBox取消后续事件 [英] MessageBox in Validating event cancels subsequent events

查看:76
本文介绍了验证事件中的MessageBox取消后续事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在验证事件中显示一个消息框会取消

后续事件。在下面的程序中,如果在按钮1的验证事件中打开一个对话框,则按钮2的点击事件不会触发
。我在做什么?b $ b这里有什么不对吗?

谢谢

Al


进口系统
导入system.windows.forms

''创建表单,添加两个按钮和事件处理程序。

''点击按钮2接收按钮1验证

''事件但不是按钮2'的点击事件。 MessageBox

''似乎会杀死点击事件。

模块ValidateTest

Sub Main()

Dim frm作为新表格()

Dim btn As New Button

btn.Text =" One"

btn.Parent = frm

AddHandler btn.Validating,AddressOf BtnValidating

btn =新按钮

btn.Left = btn.Width + 3

btn.Text =" Two"

btn.Parent = frm

AddHandler btn.Click,AddressOf BtnClick


Application.Run(frm)

End Sub


Private Sub BtnValidating(ByVal sender As Object,

ByVal e As System .ComponentModel.CancelEventArgs)

MessageBox.Show(" BtnValidating event")

End Sub


Private Sub BtnClick(ByVal发件人作为对象,ByVal e As

System.EventArgs)

MessageBox.Show(" BtnClick event")

End Sub
结束模块

Hi,

It appears displaying a messagebox in a validating event will cancel the
subsequent event. In the program below, button 2''s click event doesn''t fire
if you open a dialog box in button 1''s validating event. Am I doing
something wrong here?
Thanks
Al

Imports system
Imports system.windows.forms
'' Create a form, add two buttons and event handlers.
'' Click on Button 2 to receive Button 1 validating
'' event but not button 2''s click event. MessageBox
'' appears to kill the click event.
Module ValidateTest
Sub Main()
Dim frm As New Form()
Dim btn As New Button
btn.Text = "One"
btn.Parent = frm
AddHandler btn.Validating, AddressOf BtnValidating

btn = New Button
btn.Left = btn.Width + 3
btn.Text = "Two"
btn.Parent = frm
AddHandler btn.Click, AddressOf BtnClick

Application.Run(frm)
End Sub

Private Sub BtnValidating(ByVal sender As Object,
ByVal e As System.ComponentModel.CancelEventArgs)
MessageBox.Show("BtnValidating event")
End Sub

Private Sub BtnClick(ByVal sender As Object, ByVal e As
System.EventArgs)
MessageBox.Show("BtnClick event")
End Sub
End Module

推荐答案

Al Santino写道:
Al Santino wrote:

在验证事件中显示消息框将取消

后续事件。在下面的程序中,如果在按钮1的验证事件中打开一个对话框,则按钮2的点击事件不会触发
。我在做什么?b $ b这里有什么不对吗?
It appears displaying a messagebox in a validating event will cancel the
subsequent event. In the program below, button 2''s click event doesn''t fire
if you open a dialog box in button 1''s validating event. Am I doing
something wrong here?



我不确定我是否理解这个问题。当按钮1的验证事件触发时,为什么会触发第二个按钮'

点击事件?

I''m not sure I understand the problem. Why would the second button''s
click event be fired when the Validating event for button 1 fires?


>

< code snipped>
>
<code snipped>


" Chris Dunaway" < du ****** @ gmail.com写信息

新闻:11 ********************** @ n13g2000cwa .googlegr oups.com ...
"Chris Dunaway" <du******@gmail.comwrote in message
news:11**********************@n13g2000cwa.googlegr oups.com...

Al Santino写道:
Al Santino wrote:

>它显示为验证事件中的消息框将取消
后续事件。在下面的程序中,如果您在按钮1的验证事件中打开一个对话框,则按钮2的点击事件不会启动。我在这里做错了吗?
>It appears displaying a messagebox in a validating event will cancel the
subsequent event. In the program below, button 2''s click event doesn''t
fire
if you open a dialog box in button 1''s validating event. Am I doing
something wrong here?



我不确定我是否理解这个问题。当按钮1的验证事件触发时,为什么第二个按钮的'

点击事件会被触发?


I''m not sure I understand the problem. Why would the second button''s
click event be fired when the Validating event for button 1 fires?


>>
< code snipped>
>>
<code snipped>



好​​吧,我认为它会触发,因为它应该是如何工作的。


如果您在验证处理程序中删除了MessageBox调用,则单击事件

将触发按钮2.我的理解是第二个按钮的事件
除非您在验证事件中将取消arg设置为true,否则
应该触发

处理程序。

Well, I thought it would fire because that was how it''s supposed to work.

If you remove the MessageBox call in the validation handler the click event
fires for button 2. My understanding is that the second button''s event
should fire unless you set the cancel arg to true in the validation event
handler.



" Chris Dunaway" < du ****** @ gmail.com写信息

新闻:11 ********************** @ n13g2000cwa .googlegr oups.com ...

"Chris Dunaway" <du******@gmail.comwrote in message
news:11**********************@n13g2000cwa.googlegr oups.com...

Al Santino写道:
Al Santino wrote:

>它显示为验证事件中的消息框将取消
后续事件。在下面的程序中,如果您在按钮1的验证事件中打开一个对话框,则按钮2的点击事件不会启动。我在这里做错了吗?
>It appears displaying a messagebox in a validating event will cancel the
subsequent event. In the program below, button 2''s click event doesn''t
fire
if you open a dialog box in button 1''s validating event. Am I doing
something wrong here?



我不确定我是否理解这个问题。当按钮1的验证事件触发时,为什么第二个按钮的'

点击事件会被触发?


I''m not sure I understand the problem. Why would the second button''s
click event be fired when the Validating event for button 1 fires?


>>
< code snipped>
>>
<code snipped>



其实我并不是说它应该在验证事件发生时触发

但由于验证事件没有将取消参数

设置为true,因此它会触发。

Actually I''m not suggesting it should fire WHEN the validating event fires
but AFTER it fires since the validating event didn''t set the cancel argument
to true.


这篇关于验证事件中的MessageBox取消后续事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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