zoukankan      html  css  js  c++  java
  • EventHandler委托与自定义委托

    http://blog.csdn.net/uuxyz/article/details/7175248

     

    EventHandler委托与自定义委托

    自定义委托: 

    //1、  
    public delegate void UcSavedEventHanler(bool isSuccess);  
    //2、  
    public event UcSavedEventHanler OnUcSaved;  
    //3、  
    UcEditor1(用户控件).OnUcSaved+= new UcSavedEventHanler(UcEditor1_OnUcSaved);  
    void UcEditor1_OnUcSaved(bool isSuccess)  
    {  
        //todo:  
    } 

      

    EventHandler委托: 

    //2.1、
    public event EventHandler OnUcSaved;
    //2.2、
    public class SavedEventArgs: EventArgs
    {
        public SavedEventArgs(bool isSuccess)
        {
    this.isSuccess= isSuccess;   
        }
        public bool isSuccess;   
    }//end of class SavedEventArgs
    //3、  
    UcEditor1(用户控件).OnUcSaved+= new EventHandler(UcEditor1_OnUcSaved);
    
    void UcEditor1_OnUcSaved(object sender,EventArgs e)  
    {  
        //todo:  
    }  

      

    1:EventHandler实际上就是一个特殊的委托,它是由.NET预定义好的一个委托,它的形式是固定的。EventHandler的定义原形类似于:
    delegate void EventHandler(object sender,EventArgs e);
    如Click事件 

    btnVal0.Click += new EventHandler(but_Click);
    void but_Click(object sender, EventArgs e)
    {
        //todo
    }

    2:使用EventHandler时,处理函数的返回值必须是Void类型,而使用Deleagate则没有这个限制。

    3:Delegate相当于一个函数的指针,用于绑定的函数返回值和参数列表要符合Delegate声明时的要求。

  • 相关阅读:
    设置VS2017背景图片
    NuGet的简单使用
    C#6.0,C#7.0新特性
    openFileDialog的Filter属性设置
    C# 获取当前路径7种方法
    正则表达式总结
    IDEA设置switch/case代码块自动补齐
    CentOS7使用yum安装RabbitMQ
    vue react 路由history模式刷新404问题解决方案
    @Component, @Repository, @Service的区别
  • 原文地址:https://www.cnblogs.com/gsk99/p/4986354.html
Copyright © 2011-2022 走看看