根据文件事件名 获取控件的绑定事件 (先取消事件,然后在绑定事件)
来源:互联网 发布:炉石传说for mac 国服 编辑:程序博客网 时间:2024/06/11 20:40
/// <summary> /// 判断控件上是否有某个事件 /// </summary> /// <param name="eventName"></param> /// <param name="aComboBoxText"></param> /// <returns></returns> private bool IsItemExists(string[] eventName, string aComboBoxText) { List<Delegate> dList = new List<Delegate>(); List<EventInfo> eList = new List<EventInfo>(); bool IsItemExists = false; foreach (string item in eventName) { PropertyInfo propertyInfo = _ComboBox.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic); EventHandlerList eventList = (EventHandlerList)propertyInfo.GetValue(_ComboBox, null); FieldInfo fieldInfo = _ComboBox.GetType().GetField(string.Format("EVENT_{0}", item.ToUpper()), BindingFlags.Static | BindingFlags.NonPublic); Delegate d = eventList[fieldInfo.GetValue(_ComboBox)]; EventInfo eventInfo = _ComboBox.GetType().GetEvent(item); if (d != null) { foreach (Delegate temp in d.GetInvocationList()) { eventInfo.RemoveEventHandler(_ComboBox, temp); } dList.Add(d); eList.Add(eventInfo); } } if (!String.IsNullOrEmpty(aComboBoxText)) { for (int i = 0; i < _ComboBox.Items.Count; i++) { PropertyInfo[] pro = _ComboBox.Items[i].GetType().GetProperties(); if (pro.Any(p => p.GetValue(_ComboBox.Items[i], null).Equals(aComboBoxText))) { IsItemExists = true; _ComboBox.SelectedIndex = i; break; } } } if (dList.Count > 0) { for (int i = 0; i < dList.Count; i++){ if (dList[i] != null) { foreach (Delegate temp in dList[i].GetInvocationList()) { eList[i].AddEventHandler(_ComboBox, temp); } } } } return IsItemExists; }
阅读全文
0 0
- 根据文件事件名 获取控件的绑定事件 (先取消事件,然后在绑定事件)
- ContextMenuStrip在点击事件里,获取绑定的控件源
- 查看控件的事件绑定
- jQuery 控件事件的绑定和取消操作
- jQuery 控件事件的绑定和取消操作
- 绑定控件事件
- Jquery控件绑定事件
- iOS控件绑定事件
- HTML 控件绑定事件
- js取消默认事件和事件绑定
- dojo中取消事件绑定
- jquery取消和绑定事件
- jQuery事件绑定与取消
- 标签事件的绑定和取消
- JavaScript事件的绑定与取消和事件监听
- 在数据绑定控件的DataBound事件中获取某绑定字段值
- 绑定事件
- 绑定事件
- windows输入法打出的字母空隙很大怎么办?
- 修复 Ubuntu apt 更新时签名无效的问题
- 欢迎使用CSDN-markdown编辑器
- arguments
- Webpack基础之四个核心介绍
- 根据文件事件名 获取控件的绑定事件 (先取消事件,然后在绑定事件)
- 简单工厂模式
- 执行上下文
- 天津松下空调,最低只需1150起
- 第一个Jsp程序,Hello World
- C++之 iterator_traits
- ArcGIS API for JavaScript——给图层添加标注
- 启动 tensorBoard
- Spring 接管 Hibernate 配置 延迟加载