473,326 Members | 2,012 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,326 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 1741
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.