楼主添加订阅,然后立马就取消。
应该直接
panel.DoubleClick = new EventHandler((sender, e) =>{
         
}就行了,建议试一下。

解决方案 »

  1.   

    楼主添加订阅,然后立马就取消。
    应该直接
    panel.DoubleClick = new EventHandler((sender, e) =>{
             
    }就行了,建议试一下。c#里面的事件无法用=赋值啊
      

  2.   

    Action<object, EventArgs> pro = null;
    pro = (sender, e) =>
    {
        //.......
        panel.DoubleClick -= pro;
    };
    panel.DoubleClick += pro
      

  3.   


    panel1.DoubleClick += new EventHandler(
        (sender1, e1)=>
        {
            //......        Type t = panel1.GetType();
            PropertyInfo pi = t.GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
            EventHandlerList ehl = (EventHandlerList)pi.GetValue(panel1, null);
            FieldInfo fieldInfo = (typeof(Control)).GetField("EventDoubleClick", BindingFlags.Static | BindingFlags.NonPublic);
            Delegate d = ehl[fieldInfo.GetValue(null)];
            if (d != null)
            {
                foreach (Delegate temp in d.GetInvocationList())
                {
                    StackTrace st = new StackTrace(true);
                    if (temp.Method == st.GetFrame(0).GetMethod())
                        ehl.RemoveHandler(fieldInfo.GetValue(null), temp);
                }
            } 
        }
    );           参考:
    http://social.microsoft.com/Forums/zh-CN/9211ba35-001f-4319-a8e6-96e53995fbf9/c-?forum=visualcshartzhchs
    http://www.csharpwin.com/csharpspace/10743r4702.shtml
      

  4.   

    楼主添加订阅,然后立马就取消。
    应该直接
    panel.DoubleClick = new EventHandler((sender, e) =>{
             
    }就行了,建议试一下。c#里面的事件无法用=赋值啊
    对不起,我搞错了,把匿名委托改一下就可以,4楼的方法应该可以解决了。
    panel.DoubleClick -= pro;什么时候取消订阅,什么时候就可以用
      

  5.   

    在窗体上添加3个按钮,然后编写如下代码:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Reflection;namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                button3.Click += (a, b) => MessageBox.Show("ok");
            }        private void button2_Click(object sender, EventArgs e)
            {
                var handlers = GetObjectEventList(button3, "EventClick", typeof(Control));
                foreach (var item in handlers.Select(x => x as EventHandler)) 
                    button3.Click -= item;
            }        private Delegate[] GetObjectEventList(object p_Object, string p_EventName, Type p_EventType)
            {
                PropertyInfo _PropertyInfo = p_Object.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
                if (_PropertyInfo != null)
                {
                    object _EventList = _PropertyInfo.GetValue(p_Object, null);
                    if (_EventList != null && _EventList is EventHandlerList)
                    {
                        EventHandlerList _List = (EventHandlerList)_EventList;
                        FieldInfo _FieldInfo = p_EventType.GetField(p_EventName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
                        if (_FieldInfo == null) return null;
                        Delegate _ObjectDelegate = _List[_FieldInfo.GetValue(p_Object)];
                        if (_ObjectDelegate == null) return null;
                        return _ObjectDelegate.GetInvocationList();
                    }
                }
                return null;
            }
        }
    }
      

  6.   


     EventHandler handler = (object sender1, EventArgs e1) =>
            {
                MessageBox.Show("regist");
            };        private void button1_Click(object sender, EventArgs e)
            {
                this.button3.Click += handler;
            }        private void button2_Click(object sender, EventArgs e)
            {
                this.button3.Click -= handler;
            }