![]() |
|
Event Handling in C#, Free online C# Programming Tutorial... |
| Lessons | C# Events |
|
Now consider the following example: delegate void SimpleButtonClickHandler();
class MyButton
{
public event SimpleButtonClickHandler MyButtonClicked;
public void SimulateButtonClick()
{
if (MyButtonClicked != null)
{
ButtonClicked();
}
}
...
}
A method in another class can then subscribe to the event by adding one of its methods to the event delegate:MyButton b = new MyButton(); b.ButtonClicked += MyClickHandler; Note that despite the fact that the event is declared as public, it cannot be directly fired from anywhere except in the class containing the event. Our C# Programming Tutorial for Java and C++ Programmers ends here. How did you find our efforts? Please let us know at pickatutorial@yahoo.com | Tutorial author: farooq_fl@yahoo.com More C# Programming Tutorials |