"把手,QUOT;题 [英] "Handles" Question
问题描述
这个问题与手柄有关。例程的一部分,用于
示例:
处理Button1.Click
在Form2上(用户控件)我有一个按钮。这是它的代码:
Public Sub Button1_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理Button1点击
''...
结束子
好的,现在在Form1上,我有一个菜单。其中一个菜单项需要行动
像Button1一样被点击。
我想通过添加以下内容添加到Handles部分:
处理Button1.Click,Menuitem1.Click
如果按钮和menuitem在同一个表单上,这将有效。但是
他们有不同的形式。我收到一条错误,上面写着句柄条款
需要一个WithEvents变量。我该怎么办?
感谢您的帮助!
John
This question is regarding the "Handles" part of a routine, for
example:
Handles Button1.Click
On Form2 (a User Control) I have a button. Here''s it''s code:
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
''...
End Sub
Ok, now on Form1, I have a Menu. One of the menu items needs to act
like Button1 was clicked.
I would like to add to the Handles section by adding:
Handles Button1.Click, Menuitem1.Click
This would work if the button and menuitem were on the same form. But
they are on different forms. I get an error saying "Handles clause
requires a WithEvents variable". How do I go about this?
Thanks for your help!
John
推荐答案
" johnb41" <或**** @ informatik.com> schrieb:
"johnb41" <or****@informatik.com> schrieb:
我想通过添加以下内容添加到Handles部分:
Handles Button1.Click,Menuitem1.Click
如果按钮和menuitem,这将有效是在同一个表格上。但是他们的形式各不相同。我收到一条错误,说Handles clause
需要一个WithEvents变量。我该如何解决这个问题?
I would like to add to the Handles section by adding:
Handles Button1.Click, Menuitem1.Click
This would work if the button and menuitem were on the same form. But
they are on different forms. I get an error saying "Handles clause
requires a WithEvents variable". How do I go about this?
请查看文档中的AddHandler语句。您可以使用
此语句在运行时向对象的事件添加处理程序。
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http://classicvb.org/请愿/>
Take a look at the ''AddHandler'' statement in the documentation. You can use
this statement to add a handler to an object''s event at runtime.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
John,
有很多方法可以强制按钮的点击事件。
其中一些
button1.performclick
ButtonClick(什么也没有)
或者创建一个额外的sub并从你的两个活动开始
(可能是文档中最好的方式)
我希望这有帮助,
Cor>
John,
There are plenty of methods to force a click event of a button.
Some of them
button1.performclick
ButtonClick(nothing, nothing)
Or to create an extra sub and start that from your both events
(probably for the documentation the best way)
I hope this helps,
Cor>
" Cor Ligthert" <无************ @ planet.nl> schrieb:
"Cor Ligthert" <no************@planet.nl> schrieb:
ButtonClick(什么也没有)
ButtonClick(nothing, nothing)
一如既往:/从不这样做!
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http://classicvb.org/petition/>
As always: /Never/ do that!
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
这篇关于"把手,QUOT;题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!