G
Gary Brown
Hi,
I dynamically connect a MDI parent's toolstrip button to a
child event handler by calling the following member at
the child's Activated and Deactivate events. It looks simple
enough but I'm getting multiple calls to the child's event
handler when the toolstrip button is pressed. The number
of calls increases with the number of times the child is
(de)activated. The behavior is consistent with the handler
be added to a list to be called when the event is triggered
(a behavior I haven't seen documented) but never removed.
Can someone explain what's happening and how to correct it?
The member walks through the list of toolstrip items. If an
item's name matches the given name the event handler is set
or removed.
The code is:
// Called by a child form to en(dis)able a toolbar item and (re)set its
event handler
public void EnableToolBarItem (bool _bEnabled, string _Name,
EventHandler _Handler)
{
for each (ToolStripItem Item in toolStripOTRdb.Items)
if (Item.Text == _Name)
{
Item.Enabled = _bEnabled;
if (_bEnabled)
Item.Click += new System.EventHandler(_Handler);
else
Item.Click -= new System.EventHandler(_Handler);
}
} // EnableToolBarItem
_bEnabled is true for Activated, false for Deactivate. The other
parameters are identical for both calls.
Thanks,
Gary
I dynamically connect a MDI parent's toolstrip button to a
child event handler by calling the following member at
the child's Activated and Deactivate events. It looks simple
enough but I'm getting multiple calls to the child's event
handler when the toolstrip button is pressed. The number
of calls increases with the number of times the child is
(de)activated. The behavior is consistent with the handler
be added to a list to be called when the event is triggered
(a behavior I haven't seen documented) but never removed.
Can someone explain what's happening and how to correct it?
The member walks through the list of toolstrip items. If an
item's name matches the given name the event handler is set
or removed.
The code is:
// Called by a child form to en(dis)able a toolbar item and (re)set its
event handler
public void EnableToolBarItem (bool _bEnabled, string _Name,
EventHandler _Handler)
{
for each (ToolStripItem Item in toolStripOTRdb.Items)
if (Item.Text == _Name)
{
Item.Enabled = _bEnabled;
if (_bEnabled)
Item.Click += new System.EventHandler(_Handler);
else
Item.Click -= new System.EventHandler(_Handler);
}
} // EnableToolBarItem
_bEnabled is true for Activated, false for Deactivate. The other
parameters are identical for both calls.
Thanks,
Gary