事件简单示例


1
public partial class TestForm : Form 2 { 3 public TestForm() 4 { 5 InitializeComponent(); 6 } 7 8 private void TestForm_Load(object sender, EventArgs e) 9 { 10 TestClass.testDelegateEvent += new TestClass.TestDelegate(TestClass_testDelegateEvent); //1 11 TestClass tc = new TestClass();//2 12 tc.GetInfo("aaaa");//3 13 } 14 15 public void TestClass_testDelegateEvent(string msg) 16 { 17 msg += "!@#$";//7 18 MessageBox.Show(msg);//8 19 } 20 } 21 22 public class TestClass 23 { 24 public delegate void TestDelegate(string msg); 25 public static event TestDelegate testDelegateEvent; 26 27 public void GetInfo(string msg) 28 { 29 msg += "1234567890";//4 30 if (testDelegateEvent != null)//5 31 testDelegateEvent(msg);//6 32 } 33 }

C#事件简单示例,//1  //2  ....表示执行顺序

posted @ 2013-06-14 16:36  J.Y  阅读(158)  评论(0编辑  收藏  举报