473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Event Generating Multiple Handler Calls

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
Oct 6 '06 #1
2 1392
Gary,

Before I forget, one of the reasons to use Ajax is to get the winforms
behaviour on a webpage.

Cor

"Gary Brown" <ga********@charter.netschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
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


Oct 6 '06 #2
Sorry added to the wrong thread
"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:ey**************@TK2MSFTNGP04.phx.gbl...
Gary,

Before I forget, one of the reasons to use Ajax is to get the winforms
behaviour on a webpage.

Cor

"Gary Brown" <ga********@charter.netschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
>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



Oct 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
18
by: Elder Hyde | last post by:
Hey all, A class of mine needs to tell the outside world when its buffer is not empty. The problem is that C# seems to force you to put the event-raising code in the base class. To illustrate,...
12
by: Jack Russell | last post by:
My unstanding of all VB up to and including vb6 is that an event could not "interrupt" itself. For instance if you had a timer event containing a msgbox then you would only get one message. ...
3
by: Kenichi | last post by:
hello, i'm still new to vs i have a question, how can i clear my event like to set that to null ? i would like to do something like this without knowing what is the event handler before ex:...
5
by: Chris | last post by:
Is there any way you can dynamically add an event and then some code. I get it that you could, in your code, add a control and dynamically add an event handler for e.g. the click event. However the...
5
by: J | last post by:
I am having problems dynamically adding more than one event handler to an input. I have tried the Javascript included at the bottom. The lines inp.attachEvent('onkeyup',...
0
by: Steven C | last post by:
Hello: I have a Windows Forms datagrid, which is populated with data from a SQL Server database. On that grid, I have both an EDIT button and a DEL button. I used code to wire up a custom...
4
by: eggie5 | last post by:
I have this even handler (using prototype.js): showCommentsLinks.observe('click', function(event) { alert('hi') }); It's attaching to a link element: <a id="showCommentsLink"...
3
by: =?Utf-8?B?ZWFndWlsYXI=?= | last post by:
Hi, I am trying to dynamically generate a menu, based on entries on a text or xml file. The text file contains the "tree" after which the menu will need to be created. Something like the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.