您当前的位置: 首页 >  c#

暂无认证

  • 0浏览

    0关注

    101061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C#事件-定义事件

发布时间:2010-11-22 00:15:00 ,浏览量:0

具体方法:

  1. 定义事件
    • 委托定义: public delegate void EventFountion(Param param);
    • 事件定义: public event EventFountion eventFountion;
    • 调用事件: if (eventFountion!= null) eventFountion(this.param);
  2. 使用事件
    • 事件触发后的方法 public void a_eventFountion(Param param){ ... }
    • 注册事件 ClassA a=new ClassA(); a.eventFountion+=new ClassA.EventFountion(a_eventFountion);

实例代码:

  1. 自定义事件 class ClassA{    //委托定义:    public delegate void EventFountion(Param param);    //事件定义:    public event EventFountion eventFountion;       //调用事件:    public void init(){    if (eventFountion!= null) eventFountion(this.param);    ...    }    ... }
  2. 注册事件 class ClassB{       //调用事件:    public void fountion(){    ClassA a=new ClassA();    a.eventFountion+=new ClassA.EventFountion(a_eventFountion);    }    public void a_eventFountion(Param param){    ....    }    ... }

关注
打赏
1655516835
查看更多评论
立即登录/注册

微信扫码登录

0.0803s