C # Events

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.