Main Site Documentation

Event EventHandler in VS2012


#1

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.


#2

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


#3

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:


#4

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.


#5

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


#6

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