解决方案 »

  1.   

                MouseDown += Down;
                MessageBox.Show(getDelegateByControl(this, "EventMouseDown").Method.Name); //显示Down
    其中的getDelegateByControl:
            Delegate getDelegateByControl(Control Control, string EventName)
            {
                var events =
                    typeof(Control).GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Control)
                        as EventHandlerList;            var key = typeof(Control).GetField(EventName, BindingFlags.Static | BindingFlags.NonPublic);
                if (key == null)
                {
                    throw new ArgumentException("提供的事件名不存在。", "EventName");
                }            return events[key.GetValue(null)];
            }
      

  2.   

    public Form3()
            {
                InitializeComponent();            button1.MouseClick += new MouseEventHandler(button1_MouseClick);
                
                foreach (Control c in this.Controls) 
                {
                    if (c is Button) 
                    {
                        Button btn = c as Button;
                        if(btn.Name == "button1")
                        {
                            Delegate[] _ControlDelegate = GetObjectEventList(button1, "EventMouseClick");
                            Delegate d = _ControlDelegate[0];
                            MethodInfo info = d.Method;
                            string str = info.Name;
                        }                    
                    }
                }
            }        private Delegate[] GetObjectEventList(Control p_Control, string p_EventName)
            {
                PropertyInfo _PropertyInfo = p_Control.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
                if (_PropertyInfo != null)
                {
                    object _EventList = _PropertyInfo.GetValue(p_Control, null);
                    if (_EventList != null && _EventList is EventHandlerList)
                    {
                        EventHandlerList _List = (EventHandlerList)_EventList;
                        FieldInfo _FieldInfo = (typeof(Control)).GetField(p_EventName, BindingFlags.Static | BindingFlags.NonPublic);
                        if (_FieldInfo == null) return null;
                        Delegate _ObjectDelegate = _List[_FieldInfo.GetValue(p_Control)];
                        if (_ObjectDelegate == null) return null;
                        return _ObjectDelegate.GetInvocationList();
                    }
                }
                return null;
            }         void button1_MouseClick(object sender, MouseEventArgs e)
            {
                throw new NotImplementedException();
            }
      

  3.   

    上面代码中string str = info.Name;   str的值为button1_MouseClick
      

  4.   

    你的代码中的typeof(Control).GetField(EventName, BindingFlags.Static | BindingFlags.NonPublic)这一句
    我改成了typeof(Control).GetFields(BindingFlags.Static | BindingFlags.NonPublic)竟然发现,这个集合里面没有一个元素
      

  5.   

    你这个代码的第一段我改了一下是如下Delegate[] _ControlDelegate = GetObjectEventList(this.Controls[1], "EventMouseDown");
                Delegate d = _ControlDelegate[0];
                MethodInfo info = d.Method;
                string str = info.Name;
    然后运行的时候_ControlDelegate这个值为空
      

  6.   

    其他的都很正常,但是Delegate _ObjectDelegate = _List[_FieldInfo.GetValue(p_Control)];运行到里的时候,右边的值为空
      

  7.   

    你这个代码的第一段我改了一下是如下Delegate[] _ControlDelegate = GetObjectEventList(this.Controls[1], "EventMouseDown");
                Delegate d = _ControlDelegate[0];
                MethodInfo info = d.Method;
                string str = info.Name;
    然后运行的时候_ControlDelegate这个值为空你确定你的这个this.Controls[1]注册了MouseDown事件?
      

  8.   

    好吧,我脑残了,我是再设计页面点击的事件,想着这个this.Controls[1]是覆盖窗体的,还以为就是这个注册了MouseDown事件,没想到刚刚一看才发现,原来是form注册的事件不是this.Controls[1]这个