By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,572 Members | 1,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,572 IT Pros & Developers. It's quick & easy.

Event Handler

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.