473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Event Handler

Fei
HI,

I have a problem about EventHandler. I have a form with one button on it.
I implement Button's click event. Is there a way I can determine whether I
implement a handler for this event at runtime ? I try to use

1. me.Events.Item(Button1) . This will return Nothing

2. me.Events.Item(Button1.Click). This will throw out an exception
saying 'Click' is not a member of 'Button'

Please help. Thanks !

Fei


Nov 21 '05 #1
2 1745
First create your ebvent handler method, but do do not attach it to any
event at this stage:

-- Code Starts --
Private Sub TestRuntimeEventHandler(ByVal sender As System.Object, ByVal e
As System.EventArgs)
' Insert your event handliong code here
End Sub
-- Code ends --

Make sure the method has these parameters otherwise it will not work,

And then at runtime, whereever you want to add the event handler, add the
following code:

-- Code Starts --
AddHandler Button1.Click, AddressOf TestRuntimeEventHandler
-- Code Ends --

The AddHandler takes the event you want to handle and the name of the method
to handle it prefixed by 'AddressOf ' as parameters.

If you want to remove the event handler at runtime you use RemoveHandler is
a similar way.

Hope this helps.
"Fei" <fw***@NOSPAMcsystemssoftware.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
HI,

I have a problem about EventHandler. I have a form with one button on it. I implement Button's click event. Is there a way I can determine whether I
implement a handler for this event at runtime ? I try to use

1. me.Events.Item(Button1) . This will return Nothing

2. me.Events.Item(Button1.Click). This will throw out an exception
saying 'Click' is not a member of 'Button'

Please help. Thanks !

Fei

Nov 21 '05 #2
Fei
Matt.

What Shall I put in Events.Item ?
Events.Item(*What is sppposed to be here*) ?
Thanks !
"Matt S" <ma**@toomuchspamalready.com> wrote in message
news:OS**************@TK2MSFTNGP10.phx.gbl...
First create your ebvent handler method, but do do not attach it to any
event at this stage:

-- Code Starts --
Private Sub TestRuntimeEventHandler(ByVal sender As System.Object, ByVal e
As System.EventArgs)
' Insert your event handliong code here
End Sub
-- Code ends --

Make sure the method has these parameters otherwise it will not work,

And then at runtime, whereever you want to add the event handler, add the
following code:

-- Code Starts --
AddHandler Button1.Click, AddressOf TestRuntimeEventHandler
-- Code Ends --

The AddHandler takes the event you want to handle and the name of the method to handle it prefixed by 'AddressOf ' as parameters.

If you want to remove the event handler at runtime you use RemoveHandler is a similar way.

Hope this helps.
"Fei" <fw***@NOSPAMcsystemssoftware.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
HI,

I have a problem about EventHandler. I have a form with one button on

it.
I implement Button's click event. Is there a way I can determine whether I implement a handler for this event at runtime ? I try to use

1. me.Events.Item(Button1) . This will return Nothing

2. me.Events.Item(Button1.Click). This will throw out an exception saying 'Click' is not a member of 'Button'

Please help. Thanks !

Fei


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
6
by: vbMark | last post by:
If I have a control, for example a CheckedListBox, how do I add and event to code, for example that a box has been checked by the user? Thanks
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
3
by: Beth | last post by:
in the following: this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click); if I saw an equation, such as y +=x; then y = y+x. But what is the meaning in the event handler. I...
5
by: Richard Grant | last post by:
Hi, I need to "save" in a variable the event handler sub of a control's event, then perform some process, and finally "restore" the originally saved event handler. Example in pseudo-code: 1)...
1
by: tdan | last post by:
I do not know how to get Event.stopObserving() to work in the context I am using it. I am displaying a Color Selection Table and attaching 2 events: 1. onmouseover to display the color to the user...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
2
by: =?Utf-8?B?UlJK?= | last post by:
Hello, I would like to add the Paint handler to the form. How to do it? Thanks in advance.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.