如何给自定义控件添加事件
2009-03-30 08:18
204 查看
代碼如下:
在自定义控件中这样声明以后就可以直接在使用的地方为其写CellClick事件代码了。
#region 为复合控件添加事件 //声明复合控件的事件 public event DataGridViewCellEventHandler CellClick; //委托处理的事件代码 protected virtual void OnCellClick(DataGridViewCellEventArgs e) { DataGridViewCellEventHandler dg = CellClick; //如果事件不為空 if (dg != null) { dg(dataGV, e);//調用事件 } } #endregion #region 复合函数的构造函数 /// <summary> /// 构造函数 /// </summary> public UserDataGridView() { InitializeComponent(); //为CellClick事件绑定一个委托事件 dataGV.CellClick += delegate(object sender, DataGridViewCellEventArgs e) { OnCellClick(e); }; } #endregion
在自定义控件中这样声明以后就可以直接在使用的地方为其写CellClick事件代码了。
相关文章推荐
- c# 自定义控件如何在属性栏添加自定义事件
- ASP.NET2.0中的ClientScriptManager 类用法—如何添加客户端事件!
- Panel 上添加了很多control,如何避免Panel的click事件被拦截
- Unity插件之NGUI学习(6)—— 关于Widget如何添加触发事件(触发OnClick)
- 如何在fluid中添加自定义控件
- js中如何添加一个事件监听addEventListener
- 如何在natTable表格上添加双击事件
- 如何为现有控件的DependencyProperty添加Value Changed事件?
- C#如何创建自定义控件以及添加自定义属性和事件使用
- asp.net中服务器控件如何添加客户端的js事件?
- c# web 为自定义控件添加事件
- ASP.NET WEB控件如何添加控件事件的响应函数
- 如何自己添加后台事件(grvMain双击事件)
- 【“零起点”--百度地图手机SDK】如何添加地图图层+按钮事件+水平垂直布局?
- 如何为现有控件的DependencyProperty添加Value Changed事件?
- 如何在UILable上添加点击事件?
- 【百度地图API】如何给自定义覆盖物添加事件
- 如何自己添加后台事件(Gridview双击事件)
- 在GridView中添加按钮后,如何触发按钮的各种事件? [转帖]
- Silverlight自定义控件系列 – TreeView (3) 添加展开和收起事件