M
MLS
The documentation on dynamic handlers comes across as abiguous.
Perhaps somebody could help set me straight?
I have a situation where I need to dynamically create several
usercontrols of the same type within a form. This usercontrol has some
events associated with it.
For example:
Private Sub NewThingy()
'TODO clean things up better than this (removehandler and
all...)
tabMain.SelectedTab.Controls.Clear()
Dim oMyControl As New MyControl
tabMain.SelectedTab.Controls.Add(oMyControl)
' ... stuff
AddHandler oMyControl.MyEventName, AddressOf MyEventHandler
End Sub
Private Sub MyEventHandler(Parameter as string)
' ... stuff
End Sub
Now, I create four tabs, then call NewThingy within each of them.
So, I now have four instances of MyControl, all pointing at
MyEventHandler.
If one of my instances raises its event, does it fire four times due
to the four AddHandler statements? Or, would it fire only once due to
the fact that oMyControl.MyEventName is only for the one instance of
MyControl?
If I do a RemoveHandler, am I just pulling the first MyEventName off
the stack, am I removing the handler for a specific object instance,
or am I removing all instances of handlers pointing to MyEventName?
I want to be able to create and clean up these handlers properly with
these dynamically created and destroyed controls. Any help would be
appreciated.
Thanks
- mls
Perhaps somebody could help set me straight?
I have a situation where I need to dynamically create several
usercontrols of the same type within a form. This usercontrol has some
events associated with it.
For example:
Private Sub NewThingy()
'TODO clean things up better than this (removehandler and
all...)
tabMain.SelectedTab.Controls.Clear()
Dim oMyControl As New MyControl
tabMain.SelectedTab.Controls.Add(oMyControl)
' ... stuff
AddHandler oMyControl.MyEventName, AddressOf MyEventHandler
End Sub
Private Sub MyEventHandler(Parameter as string)
' ... stuff
End Sub
Now, I create four tabs, then call NewThingy within each of them.
So, I now have four instances of MyControl, all pointing at
MyEventHandler.
If one of my instances raises its event, does it fire four times due
to the four AddHandler statements? Or, would it fire only once due to
the fact that oMyControl.MyEventName is only for the one instance of
MyControl?
If I do a RemoveHandler, am I just pulling the first MyEventName off
the stack, am I removing the handler for a specific object instance,
or am I removing all instances of handlers pointing to MyEventName?
I want to be able to create and clean up these handlers properly with
these dynamically created and destroyed controls. Any help would be
appreciated.
Thanks
- mls