PC Review


Reply
Thread Tools Rate Thread

Can we add an event handler that has different delegate?

 
 
Tee
Guest
Posts: n/a
 
      9th Feb 2005
Hi,

As topic,

Can we add an event handler that has different delegate?

Example:

I have a method that takes no parameter:
public void xyz()

I would like button1 to fire that method onclick.
button1.Click += new EventHandler(xyz)

I understand that button click event should has parameter like this :
(object sender, System.EventArgs e)

But what if I want to "force" it add the method? Or at least maybe make a
convert on runtime, like convert xyz() to xyz(object sender,
System.EventArgs e), and pass in (null, null).

Can I achieve that?


Thanks,
Tee


 
Reply With Quote
 
 
 
 
Chris, Master of All Things Insignificant
Guest
Posts: n/a
 
      9th Feb 2005
Why not just overload it?
xyz(object sender, System.EventArgs e)
{
xyz(null, null)
}

xyz()
{
.....
}
Chris

"Tee" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> As topic,
>
> Can we add an event handler that has different delegate?
>
> Example:
>
> I have a method that takes no parameter:
> public void xyz()
>
> I would like button1 to fire that method onclick.
> button1.Click += new EventHandler(xyz)
>
> I understand that button click event should has parameter like this :
> (object sender, System.EventArgs e)
>
> But what if I want to "force" it add the method? Or at least maybe make a
> convert on runtime, like convert xyz() to xyz(object sender,
> System.EventArgs e), and pass in (null, null).
>
> Can I achieve that?
>
>
> Thanks,
> Tee
>
>



 
Reply With Quote
 
NuTcAsE
Guest
Posts: n/a
 
      9th Feb 2005
Short answer... No. Delegates are type safe, so they encforce the rule
that any function passed to the delegate has to implement the exact
signature. You will have to wait for anonymous methods in 2.0 to
achieve something like what you want.

In anycase, i dont see the reason why this functionality would be
required.

NuTcAsE

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between delegate and event handler Curious Microsoft Dot NET 2 20th Jul 2009 05:06 PM
Delegate and Event Handler Curious Microsoft Dot NET 2 24th Mar 2007 04:47 AM
Event handler delegate as variable steve Microsoft VB .NET 1 1st May 2006 05:40 PM
Can we add an event handler that has different delegate? Tee Microsoft Dot NET 2 9th Feb 2005 06:43 PM
delegate or event handler? ALI-R Microsoft C# .NET 6 6th Nov 2004 06:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:35 PM.