天天看点

c#事件四部曲

C#事件四部曲:

(1)定义委托

        public deligate void DoSomethingDelegate(object sender, EventArgs e);

 (2)定义事件(在类中)

        publice event DoSomethingDelegate DoSomething;

(3)引发事件(判断某个操作执行,或在某个操作执行后)

        DoSomething(object, e);

(4)定义事件处理方法并绑定到事件(在初始化时)

        ~.DoSomething += doSomethingHandler;

        private void doSomethingHandler(object sender, EventArgs e)

             {  ... }

本文转自 huohe2009 51CTO博客,原文链接:http://blog.51cto.com/zhaojie/852592