AddHandler and RemoveHandler
-
I come from C# world. Now I am in here and need a bit of help. Here is a C# program which add event handler:
private CenterTrigger_EventHandlerAdv m_CenterTriggerHandler = null;
// Sets up an event handler to handle the center trigger events.
// The event handler only needs to be registered once.
if (m_CenterTriggerHandler == null)
{
m_CenterTriggerHandler = new CenterTrigger_EventHandlerAdv(BRIReader_EventHandlerCenterTrigger);
m_BRIReader.EventHandlerCenterTrigger += m_CenterTriggerHandler;
}I convert it to VB.net.
AddHandler m_BRIReader.EventHandlerCenterTrigger, AddressOf BRIReader_EventHandlerCenterTrigger
Now in VB, how can I check if an event handler has been added? If it has, I would like to RemoveHandler.
-
I come from C# world. Now I am in here and need a bit of help. Here is a C# program which add event handler:
private CenterTrigger_EventHandlerAdv m_CenterTriggerHandler = null;
// Sets up an event handler to handle the center trigger events.
// The event handler only needs to be registered once.
if (m_CenterTriggerHandler == null)
{
m_CenterTriggerHandler = new CenterTrigger_EventHandlerAdv(BRIReader_EventHandlerCenterTrigger);
m_BRIReader.EventHandlerCenterTrigger += m_CenterTriggerHandler;
}I convert it to VB.net.
AddHandler m_BRIReader.EventHandlerCenterTrigger, AddressOf BRIReader_EventHandlerCenterTrigger
Now in VB, how can I check if an event handler has been added? If it has, I would like to RemoveHandler.
I would have a read of this How to check to see if an event exists[^]
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
-
I come from C# world. Now I am in here and need a bit of help. Here is a C# program which add event handler:
private CenterTrigger_EventHandlerAdv m_CenterTriggerHandler = null;
// Sets up an event handler to handle the center trigger events.
// The event handler only needs to be registered once.
if (m_CenterTriggerHandler == null)
{
m_CenterTriggerHandler = new CenterTrigger_EventHandlerAdv(BRIReader_EventHandlerCenterTrigger);
m_BRIReader.EventHandlerCenterTrigger += m_CenterTriggerHandler;
}I convert it to VB.net.
AddHandler m_BRIReader.EventHandlerCenterTrigger, AddressOf BRIReader_EventHandlerCenterTrigger
Now in VB, how can I check if an event handler has been added? If it has, I would like to RemoveHandler.
Visual Basic is a very forgiving and accommodating language. In keeping with the VB6 legacy, it does a lot of plumbing for you behind the scenes without ever writing a single line of code. You don't need to check if an event handler exists before calling RemoveHandler, just call it.
-
I would have a read of this How to check to see if an event exists[^]
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
Simon_Whale, Thanks for your answer. I read the article posted in your link. I get the answer after I have read the first paragraph of the third 'floor' of answer. The rest (fourth floor to the 7th floor) of article does not help me that much. (Actually I don't really understand those answers. :( ) Anyway, I just call RemoveHandler before calling AddHandler with the same set of parameters.