Event EventHandler in VS2012

When I use the “tab” to automatically generate the ButtonEventHandler, I get

 button.ButtonPressed += button_ButtonPressed; 
 void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            Debug.Print("Program test");
        }

But it should be

 button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed); 

How to solve it?

Thanks.

It is correct. VS2012 creates events different from VS2010. The code will still compile and work if you use either version.

To be fair to Tzu Hsuan, I was surprised by this myself when I moved to VS2012

Without knowing about it, you would think this was an error. :slight_smile:

this syntax for event registration has been in C# since the second generation of the language. VS2012 is now using this shorter form. I consider this a non-event.

And here i was under the impression that .Net was event driven :whistle:

1 Like

simple and stupid question, but still thanks for all your help.
Thanks