Finding existing delegates.

  • Thread starter Thread starter Martin Hart - Memory Soft, S.L.
  • Start date Start date
M

Martin Hart - Memory Soft, S.L.

Hi:

How can I find out if a particular delegate has already been assigned to a
handler?

What I'm trying to do is discover if a particular delegate has been added to
the handler before I issue a:
this.KeyDown -= new
System.Windows.Forms.KeyEventHandler(this.msEditControlKeyDown);

I know I can remove it even if it has not been added previously, and no
error is generated, but if I want to add a delegate I want to make sure that
it isn't already assigned.

TIA,
Martin.
 
Martin,

Try this

KeyEventHandler keh = new KeyEventHandler(this.msEditControlKeyDown);
bool found = false;
foreach ( Delegate d in this.KeyDown.GetInvocationList() )
if ( d.Equals( keh ) ) {
found = true;
break;
}
if ( !found )
this.KeyDown += keh;



Mattias
 
Mattias:

That's what I was looking for :-))

Thanks very much,
Regards,
Martin
 
Back
Top