1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Enabling Notifications with Events docx

1 251 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 1
Dung lượng 20,77 KB

Nội dung

Enabling Notifications with Events In the previous section, you saw how to declare a delegate type, call a delegate, and create delegate instances. However, this is only half the story. Although delegates allow you to invoke any number of methods indirectly, you still have to invoke the delegate explicitly. In many cases, it would be useful to have the delegate run automatically when something significant happens. For example, in the automated factory scenario, it could be vital to be able to invoke the stopMachinery delegate and halt the equipment if a machine overheats. In the .NET Framework, events allow you to define and trap significant actions, and arrange for a delegate to be called to handle the situation. Many classes in the .NET Framework expose events. Most of the controls that you can place on a Windows form, and the Windows Form class itself, use events to allow you to run code when, for example, the user clicks a button or types something in to a field. You can also define your own events.  . Enabling Notifications with Events In the previous section, you saw how to declare a delegate. .NET Framework expose events. Most of the controls that you can place on a Windows form, and the Windows Form class itself, use events to allow you to

Ngày đăng: 21/01/2014, 15:20

w