WinForm設置用戶控件的按鈕事件
作者:Allen_Chen
Visual Studio自帶的DataGridView跟DevExpress里面的DataGrid相比確實相差太遠了,樣式不好看不說,功能上也欠缺了很多,為了滿足用戶的需求只得做一個查找定位的功能出來勉強滿足一下用戶的需求。
項目中需要對一個DataGridView控件進行類似于Excel查找的功能,之前是使用的DevExpress里面的DataGrid,用起來倒是很方便,它的列頭可以和Excel一樣進行隨意的篩選,但是那個是收費的東東,我用了幾天破解版的,擔心以后會有影響所以還是決定換掉它,Visual Studio自帶的DataGridView跟DevExpress里面的DataGrid相比確實相差太遠了,樣式不好看不說,功能上也欠缺了很多,為了滿足用戶的需求只得做一個查找定位的功能出來勉強滿足一下用戶的需求,
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- namespace MES.Common
- {
- public partial class UserControlFind : UserControl
- {
- public UserControlFind()
- {
- InitializeComponent();
- }
- //增加 一個事件,項目里面用到這個控件的時候就可以使用這個事件了。
- [EditorBrowsable(EditorBrowsableState.Always)]
- [Browsable(true)]
- public event EventHandler U_Click;
- public void btnFindValue_Click(object sender, EventArgs e)
- {
- if (U_Click != null)
- U_Click(this, e);
- }
- }
- }
- UserControlFind u = new UserControlFind();
- //Find_Grid就是用戶控件里面的查找方法,這里直接調用它并傳入一個字符串和一個DataGridView
- u.Find_Grid(userControlFind_OP.txtValue.Text.Trim(), this.dgv);
效果如圖:
原文鏈接:http://www.cnblogs.com/allen0118/archive/2012/05/14/2498895.html
【編輯推薦】
- WPF調用Winform控件具體技巧分享
- Winform框架之字典數據管理
- 詳解Winform多線程編程基本原理
- 詳解WinForm窗體間交互的方法
- WPF與WinForm對比談 多線程編程優化是關鍵
責任編輯:彭凡
來源:
博客園