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