[Mono-winforms-list] Is it possible to overload theSystem.EventHandler?

Kornél Pál kornelpal at gmail.com
Sat Feb 3 16:12:29 EST 2007


Hi,

You should create a wrapper object that has a field that stores arg2 and has 
an instance method that matches EventHandler. If you need "this" as well you 
should store that    in the helper object as well:

this.foo.TextChanged += new System.EventHandler(new HelperObject(this, 
arg2).OnTextChanged);

Kornél

----- Original Message ----- 
From: "Sanford Armstrong" <sanfordarmstrong at gmail.com>
To: "Paul" <paul at all-the-johnsons.co.uk>
Cc: "winforms" <mono-winforms-list at lists.ximian.com>
Sent: Saturday, February 03, 2007 9:59 PM
Subject: Re: [Mono-winforms-list] Is it possible to overload 
theSystem.EventHandler?


> On 2/3/07, Paul <paul at all-the-johnsons.co.uk> wrote:
>> Hi,
>>
>> I've googled for this for a while now, but can't seem to find a way to
>> do it.
>>
>> I'm trying to pass more than one argument on a line like
>>
>> this.foo.TextChanged += new System.EventHandler(this.foo_TextChanged,
>> arg2);
>>
>> where arg2 can be just about anything. Any hints would be appreciated.
>
> Doing exactly what you describe is not possible.  If you explain what
> your goal is, then we might be able to suggest ways to achieve it.
>
> When signing up for an event, all you are doing is adding a method
> (that has the exact signature of a particular delegate -- in this
> case, System.EventHandler) to a list of methods that will be called
> when the event is fired.  So all you can do is add and remove methods
> from the event, and the methods MUST have the right signature.
>
> What do you want to do with arg2?  I am sure there is a way to get
> foo_TextChanged to be aware of it.
>
> Best,
> Sandy
> _______________________________________________
> Mono-winforms-list maillist  -  Mono-winforms-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-winforms-list 



More information about the Mono-winforms-list mailing list