link下,比如有一个事件,+=了两个方法,如何只执行第二个方法,不执行第一个?
1条回答 默认 最新
- threenewbee 2015-04-30 09:50关注
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Click += button1_Click_1;
}private void button1_Click(object sender, EventArgs e) { MessageBox.Show("button1_0"); } private void button1_Click_1(object sender, EventArgs e) { MessageBox.Show("button1_1"); } public static 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; } private void button2_Click(object sender, EventArgs e) { Delegate[] _List = GetObjectEventList(button1, "EventClick", typeof(Control)); _List[1].Method.Invoke(this, new object[] { sender, e }); } }
}
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
- ¥15 gdf格式的脑电数据如何处理matlab
- ¥20 重新写的代码替换了之后运行hbuliderx就这样了
- ¥100 监控抖音用户作品更新可以微信公众号提醒
- ¥15 UE5 如何可以不渲染HDRIBackdrop背景
- ¥70 2048小游戏毕设项目
- ¥20 mysql架构,按照姓名分表
- ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
- ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
- ¥15 linux驱动,linux应用,多线程