How to add Button.Click EventHandler?

185 views
Skip to first unread message

tom-corwin

unread,
Aug 22, 2016, 2:17:05 AM8/22/16
to Eto.Forms
Hello!

Before I get to my question, let me say I am new to C#, but have an extensive VB.NET background.

I have a Button. I am trying to add an event handler to it in normal WinForms statements. When I do this, I receive the following error:

CS0029: Cannotimplicitly convert type 'System.EventHandler' to 'System.EventHandler<System.EventArgs>'

Here are samples of the code I am writing with, that are giving me such errors:

Form1.eto.cs:
cancelButton.Click += new EventHandler(cancelButton_Click); 'This line gives me the error.

Form1.cs:
        private void cancelButton_Click(Object sender, EventArgs e)
        {

        }

I'm not sure what I'm doing wrong. Any suggestions?



eugeller

unread,
Aug 22, 2016, 3:21:06 AM8/22/16
to Eto.Forms
Try this,
cancelButton.Click += (s, e) => cancelButton_Click(s, e);

curtis

unread,
Aug 24, 2016, 11:31:11 PM8/24/16
to Eto.Forms
Remove the new EventHandler part.  Eto.Forms doesn't use EventHandler, it uses EventHandler<EventArgs> for better generics support for handling and binding to events.

E.g. cancelButton.Click += cancelButton_Click;

Hope this helps!
Curtis.

On Sunday, August 21, 2016 at 11:17:05 PM UTC-7, tom-corwin wrote:

tom-corwin

unread,
Aug 25, 2016, 12:17:14 AM8/25/16
to Eto.Forms
Thank you. This worked for me.

tom-corwin

unread,
Aug 25, 2016, 12:18:24 AM8/25/16
to Eto.Forms
Thanks for the reply.

What would the difference be in your example, and this one:

Reply all
Reply to author
Forward
0 new messages