zoukankan      html  css  js  c++  java
  • How to remove all event handlers from a control

    public partial class Form1:Form 
    { 
           
    publicForm1() 
           
    { 
               
    InitializeComponent(); 
     
                button1
    .Click+= button1_Click; 
                button1
    .Click+= button1_Click2; 
                button2
    .Click+= button2_Click; 
           
    } 
     
           
    privatevoid button1_Click(object sender,EventArgs e) 
           
    { 
               
    MessageBox.Show("Hello"); 
           
    } 
     
           
    privatevoid button1_Click2(object sender,EventArgs e) 
           
    { 
               
    MessageBox.Show("World"); 
           
    } 
     
           
    privatevoid button2_Click(object sender,EventArgs e) 
           
    { 
               
    RemoveClickEvent(button1); 
           
    } 
     
           
    privatevoidRemoveClickEvent(Button b) 
           
    { 
               
    FieldInfo f1 =typeof(Control).GetField("EventClick",  
                   
    BindingFlags.Static|BindingFlags.NonPublic); 
               
    object obj = f1.GetValue(b); 
               
    PropertyInfo pi = b.GetType().GetProperty("Events",   
                   
    BindingFlags.NonPublic|BindingFlags.Instance); 
               
    EventHandlerList list =(EventHandlerList)pi.GetValue(b,null); 
                list
    .RemoveHandler(obj, list[obj]); 
           
    } 
       
    } 
    } 

  • 相关阅读:
    SQL Server 全文搜索 配置、查询初体验
    SQL Server 触发器
    SQL Server 锁
    SQL Server 事务语法
    SQL Server 表变量和临时表的区别
    SQL Server系统存储过程
    SQL 语句转换格式函数Cast、Convert
    SQL Server 系统视图
    T-SQL 批处理
    SQL Server 分区表
  • 原文地址:https://www.cnblogs.com/hdl217/p/2238037.html
Copyright © 2011-2022 走看看