使用AddHandler [英] Using AddHandler

查看:55
本文介绍了使用AddHandler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我正在努力的应用程序,允许用户运行5

报告中的一个。报告名称在我的表格中的组合框中。我为每个报告定义了一个子

,它与组合框中显示的名称完全相同

。我在表单上有一个按钮来开始处理。

我想要做的是:当用户选择他们想要的报告从组合框运行
时,我想要动态地将相应的

子绑定到按钮的click事件。由于子名称与

相同,显示名称在框中,我想这样做:


Addhandler Button1.Click ,combobox1.text


不幸的是,这使得VB寻找一个名为combobox1.text的子,

而不是寻找在combobox1中命名的函数。文本。任何人

知道如何做我想做的事情????


-rp

I have an app I''m working on that will allow a user to run one of 5
reports. The report names are in a combobox on my form. I have a sub
defined for each report that has the exact same name as is displayed
in the combobox. I have one button on the form to start processing.
What I want to do is this: When the user selects the report they want
to run from the combobox, I want to dynamically bind the appropriate
sub to the button''s click event. Since the sub names are the same as
the display names in the box, I''m wanting to do it like this:

Addhandler Button1.Click, combobox1.text

Unfortunately, that makes VB look for a sub called "combobox1.text",
instead of looking for the function named in combobox1.text. Anyone
know how to do what I''m trying to do????

-rp

推荐答案

" Rick Palmer" < RI ********* @ welove.com> schrieb:
"Rick Palmer" <ri*********@welove.com> schrieb:
框中的显示名称,我想这样做:

Addhandler Button1.Click,combobox1.text
the display names in the box, I''m wanting to do it like this:

Addhandler Button1.Click, combobox1.text




在''combobox1.text''前添加''AddressOf''。


-

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>



Add ''AddressOf'' in front of the ''combobox1.text''.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>





1)Combobox1.text是组合框的属性。你不应该命名一个

函数或一个与控件属性相同的子元素


2)使用addhandler的地址让编译器知道在哪里找到

程序

Addhandler Button1.Click,MyofventHandler的地址


3)AddHandler只适用于不能正常工作的子程序功能。

他们必须接受与活动期望相同的论点。




------ ---------------

" Rick Palmer" < RI ********* @ welove.com>在消息中写道

news:fa ******************************** @ 4ax.com ...

我有一个我正在努力的应用程序,允许用户运行5

报告中的一个。报告名称在我的表格中的组合框中。我为每个报告定义了一个子

,它与组合框中显示的名称完全相同

。我在表单上有一个按钮来开始处理。

我想要做的是:当用户选择他们想要的报告从组合框运行
时,我想要动态地将相应的

子绑定到按钮的click事件。由于子名称与

相同,显示名称在框中,我想这样做:


Addhandler Button1.Click ,combobox1.text


不幸的是,这使得VB寻找一个名为combobox1.text的子,

而不是寻找在combobox1中命名的函数。文本。任何人

知道如何做我想做的事情????


-rp
Hi,

1) Combobox1.text is a property of a combobox. You should not name a
function or a sub the same as a property of a control

2) Use address of in addhandler so the compilier knows where to find the
procedure
Addhandler Button1.Click, Addressof MyEventHandler

3) AddHandler only works with sub routines they do not work with functions.
They must accept the same arguments as the event is expecting.

Ken
---------------------
"Rick Palmer" <ri*********@welove.com> wrote in message
news:fa********************************@4ax.com...
I have an app I''m working on that will allow a user to run one of 5
reports. The report names are in a combobox on my form. I have a sub
defined for each report that has the exact same name as is displayed
in the combobox. I have one button on the form to start processing.
What I want to do is this: When the user selects the report they want
to run from the combobox, I want to dynamically bind the appropriate
sub to the button''s click event. Since the sub names are the same as
the display names in the box, I''m wanting to do it like this:

Addhandler Button1.Click, combobox1.text

Unfortunately, that makes VB look for a sub called "combobox1.text",
instead of looking for the function named in combobox1.text. Anyone
know how to do what I''m trying to do????

-rp

就像我在上一封电子邮件中所说的那样,这将使VB找到一个名为combobox1.text的Sub

。但事实并非如此。案件是

我要调用的子名称是IN combobox1.text ....参见?

-rp

开2004年10月6日星期三20:01:46 +0200,Herfried K. Wagner [MVP]

< hi *************** @ gmx.at>写道:
Like I said in my previous email, that would make VB look for a Sub
called "combobox1.text". But that''s not the case. The case is the
name of the sub I want to call is IN combobox1.text....See?
-rp
On Wed, 6 Oct 2004 20:01:46 +0200, "Herfried K. Wagner [MVP]"
<hi***************@gmx.at> wrote:
" Rick Palmer" < RI ********* @ welove.com> schrieb:
"Rick Palmer" <ri*********@welove.com> schrieb:
框中的显示名称,我想这样做:

Addhandler Button1.Click,combobox1.text
the display names in the box, I''m wanting to do it like this:

Addhandler Button1.Click, combobox1.text



Add ''AddressOf'' in front of the ''combobox1.text''.






这篇关于使用AddHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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