C # Events
"Bo Master" anti-bone Aberdeen "original" http://www.cnblogs.com/liqingwen/p/6057301.html
A class or object can notify other classes or objects about what is happening through events. The class that sends (or raises ) an event is called the publisher, and the class that receives (or processes ) The event is called a Subscriber.
In a typical C # Windows form or WEB application, you can subscribe to events raised by controls such as buttons and list boxes.You can use the Visual C # integrated development Environment (IDE) to browse events published by controls and select the events you want to handle. The IDE automatically adds a blank event handler method and the code to subscribe to the event.
the event has the following properties
The issuer determines when the event is raised, and the Subscriber determines what response to the event.
An event can have multiple subscribers. subscribers can handle multiple events from multiple publishers.
Events that do not have subscribers will never be raised.
Events are typically used to represent user actions, such as clicking a button or a menu option in a graphical user interface.
When an event has multiple subscribers, the event handler is invoked synchronously when the event is raised. to invoke an event asynchronously
Events are based on EventHandler delegates and EventArgs base classes.
Subscription and cancellation of events
If you want to write custom code that is called when an event is raised, you can subscribe to events published by other classes. For example, you can subscribe to a button's click event so that the application performs some useful action when the user clicks the button.
1. Subscribing to events using the Visual Studio IDE
Figure Create a new WinForm project
Figure 1 The code that is created automatically when you double-click
In addition to Figure 2, the InitializeComponent method also automatically adds this line of code
C # Events