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声明时的要求。

  • 相关阅读:
    Activemq+Zookeeper集群
    Centos7 安装 ActiveMQ 5.15.1
    189. Rotate Array
    188. Best Time to Buy and Sell Stock IV
    187. Repeated DNA Sequences
    186.Reverse Words in a String II
    179. Largest Number
    174. Dungeon Game
    173. Binary Search Tree Iterator
    172. Factorial Trailing Zeroes
  • 原文地址:https://www.cnblogs.com/gsk99/p/4986354.html
Copyright © 2011-2022 走看看