this.button1.Click += new System.EventHandler(this.button1_Click_2);  //注册事件this.button1.Click-=new System.EventHandler(this.button1_Click_2);  //取消注册

解决方案 »

  1.   

    this.button1.Click-=new System.EventHandler(this.button1_Click_2);  //取消注册
      

  2.   

    using System;
    using System.IO;
    using System.Reflection;class cAuthorAttribute:Attribute
    {
    public cAuthorAttribute(string name)
       {
    m_name=name;
       }
    public string Name
    {
    get
    {
    return m_name;
    }
    set
    {
    m_name=value;
    }
    } public string Note
    {
    get
    {
    return m_note;
    }
    set
    {
    m_note=value;
    }
    }
    protected string m_name;
    protected string m_note;

    }[cAuthor("Xiongqin")]
    class cMyClass
    {
    public cMyClass()
    { } [cAuthor("Xiongqin")]
    public string Str()
    {
    return null;
    } public int m_i; [cAuthor("Xiongqin")]
    public float m_f;}class cAttributeTest
    {
    public cAttributeTest(Type theType)
    {
    m_type=theType;
    }
    public string GetAuthorName()
    {
    foreach(Attribute attrib in m_type.GetCustomAttributes(true))
    {
    cAuthorAttribute author_attrib=attrib as cAuthorAttribute;
    if(author_attrib!=null)
    return author_attrib.Name;
    }
    return null;
    } public string GetNotes()
    {
    foreach(Attribute attrib in m_type.GetCustomAttributes(true))
    {
    cAuthorAttribute author_attrib=attrib as cAuthorAttribute;
    if(author_attrib!=null)
    return author_attrib.Note;

    }
    return null;
    } public string[] GetAllMemberAutoInfo()
    {
    MemberInfo[] members=m_type.GetMembers();
    string[] result=new string[members.Length]; int n=0;
    foreach(MemberInfo meminfo in members)
    {
    string name=meminfo.Name;
    string memberType=meminfo.MemberType.ToString();
    string author=Member_Author(meminfo);
    if(author==null)
    author="Not Known";
    result[n]=memberType+":"+name+",autor: "+author;
    n++;
    }
    return result;
    } public string[] GetMemberAuthorInof(string memberName)
    {
    MemberInfo[] members=m_type.GetMember(memberName);
    string[] result=new string[members.Length];
    int n=0;
    foreach(MemberInfo meminfo in members)
    {
    string name=meminfo.Name;
    string memberType=meminfo.MemberType.ToString();
    string author=Member_Author(meminfo);
    if(author==null)
    author="Not Known";
    result[n]=memberType+":"+name+",author: "+author;
    }
    return result;
    } protected string Member_Author(MemberInfo meminfo)
    {
    foreach(Attribute attrib in meminfo.GetCustomAttributes(true))
    {
    cAuthorAttribute auth=attrib as cAuthorAttribute;
    if(auth!=null)
    return auth.Name;
    }
    return null;
    } protected Type m_type;
    }class cMyApp
    {
    public static int Main(string[] args)
    {
    cMyClass myclass=new cMyClass(); cAttributeTest attrib_test=new cAttributeTest(typeof(cMyClass)); Console.WriteLine(attrib_test.GetAuthorName());
    foreach(string str in attrib_test.GetAllMemberAutoInfo())
    Console.WriteLine(str); Console.WriteLine("***********************************************");
    foreach(string str in attrib_test.GetMemberAuthorInof("m_f"))
    {
    Console.WriteLine(str);
    }
    // Console.WriteLine(attrib_test.GetAllMemberAutoInfo()[2]);
    // Console.WriteLine(attrib_test.GetNotes());
    return 0;
    }
    }
    这段代码看明白了,特性如何用也就知道了