D
DeveloperX
I'm having a play with EventHandlerList but the documentation is a bit
ropey and I can't find any decent examples. It also doesn't seem to do
what I was led to believe it would. I was under the impression that
windows.forms controls used EventHandlerLists because generally most
events aren't consumed so this saves memory.
I can add a button to a form, and have
this.button9.Click += new System.EventHandler(this.button9_Click);
this.button9.Click += new System.EventHandler(this.button9b_Click);
which will successfully fire off both functions when the button is
clicked.
The EventHandlerList does not fire both as it keys the delegate in a
hashtable and overwrites the first reference with the second reference
(This is using AddHandler).
More confusingly in trying to get the thing running I see code all over
the internet that can't run. A VB example that used a foreach (there's
no enumerator so that can't work) and a C++ example where the
EventHandlerList returns an EventHandler (It only returns Delegates in
my tests)
I'm certain I'm right, I can see plenty of alternative ways of doing it
that would work, I'm just confused about the information I'm getting
off the internet.
So am I being fed porkies? Do Windows Forms controls use
EventHandlerList objects and if so how come their implementation allows
for += and the one in ComponentModel doesn't?
Thanks
Ian
ropey and I can't find any decent examples. It also doesn't seem to do
what I was led to believe it would. I was under the impression that
windows.forms controls used EventHandlerLists because generally most
events aren't consumed so this saves memory.
I can add a button to a form, and have
this.button9.Click += new System.EventHandler(this.button9_Click);
this.button9.Click += new System.EventHandler(this.button9b_Click);
which will successfully fire off both functions when the button is
clicked.
The EventHandlerList does not fire both as it keys the delegate in a
hashtable and overwrites the first reference with the second reference
(This is using AddHandler).
More confusingly in trying to get the thing running I see code all over
the internet that can't run. A VB example that used a foreach (there's
no enumerator so that can't work) and a C++ example where the
EventHandlerList returns an EventHandler (It only returns Delegates in
my tests)
I'm certain I'm right, I can see plenty of alternative ways of doing it
that would work, I'm just confused about the information I'm getting
off the internet.
So am I being fed porkies? Do Windows Forms controls use
EventHandlerList objects and if so how come their implementation allows
for += and the one in ComponentModel doesn't?
Thanks
Ian