zoukankan      html  css  js  c++  java
  • C#中删除控件的事件的方法类.

    方法一:
    代码
            /// <summary>
            
    /// 删除指定控件的指定事件
            
    /// </summary>
            
    /// <param name="control"></param>
            
    /// <param name="eventname"></param>
            public void ClearEvent(System.Windows.Forms.Control control, string eventname)
            {
                
    if (control == nullreturn;
                
    if (string.IsNullOrEmpty(eventname)) return;

                BindingFlags mPropertyFlags 
    = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic;
                BindingFlags mFieldFlags 
    = BindingFlags.Static | BindingFlags.NonPublic;
                Type controlType 
    = typeof(System.Windows.Forms.Control);
                PropertyInfo propertyInfo 
    = controlType.GetProperty("Events", mPropertyFlags);
                EventHandlerList eventHandlerList 
    = (EventHandlerList)propertyInfo.GetValue(control, null);
                FieldInfo fieldInfo 
    = (typeof(System.Windows.Forms.Control)).GetField("Event" + eventname, mFieldFlags);
                Delegate d 
    = eventHandlerList[fieldInfo.GetValue(control)];

                
    if (d == nullreturn;
                EventInfo eventInfo 
    = controlType.GetEvent(eventname);

                
    foreach (Delegate dx in d.GetInvocationList())
                    eventInfo.RemoveEventHandler(control, dx);

            }

    调用:ClearEvent(button1,"Click");//就会清除button1对象的Click事件的所有挂接事件。

    方法二,写一个操作类,记录添加的事件列表,删除时从事件列表中读取出来然后删除.

    代码
  • 相关阅读:
    最全的曲文检测整理
    论文速读(Chuhui Xue——【arxiv2019】MSR_Multi-Scale Shape Regression for Scene Text Detection)
    论文速读(Jiaming Liu——【2019】Detecting Text in the Wild with Deep Character Embedding Network )
    论文速读(Yongchao Xu——【2018】TextField_Learning A Deep Direction Field for Irregular Scene Text)
    【论文速读】Yuliang Liu_2017_Detecting Curve Text in the Wild_New Dataset and New Solution
    【论文速读】XiangBai_CVPR2018_Rotation-Sensitive Regression for Oriented Scene Text Detection
    【论文速读】XiangBai_TIP2018_TextBoxes++_A Single-Shot Oriented Scene Text Detector
    【论文速读】Shitala Prasad_ECCV2018】Using Object Information for Spotting Text
    【论文速读】Sheng Zhang_AAAI2018_Feature Enhancement Network_A Refined Scene Text Detector
    【论文速读】Shangbang Long_ECCV2018_TextSnake_A Flexible Representation for Detecting Text of Arbitrary Shapes
  • 原文地址:https://www.cnblogs.com/queen/p/1789539.html
Copyright © 2011-2022 走看看