Created
March 29, 2012 22:14
-
-
Save dtryon/2244284 to your computer and use it in GitHub Desktop.
Simple event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| public class OnLoadTest | |
| { | |
| static void Main() | |
| { | |
| Page page = new Page(); | |
| //Wire up the event delegate | |
| page.Load += new Page.OnLoadHandler(MyHandler); | |
| //Fire the event | |
| page.Initialize(); | |
| Console.WriteLine("Press <enter> to quit"); | |
| Console.ReadLine(); | |
| } | |
| static void MyHandler(object sender, EventArgs e) | |
| { | |
| Console.WriteLine("In MyHandler"); | |
| } | |
| } | |
| public class Page | |
| { | |
| public void Initialize() | |
| { | |
| //Do a few things | |
| OnLoad(); | |
| } | |
| public delegate void OnLoadHandler(object sender, EventArgs e); | |
| public event OnLoadHandler Load; | |
| protected void OnLoad() | |
| { | |
| if (Load != null) | |
| { | |
| EventArgs args = new EventArgs(); | |
| Load(this, args); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment