您好,登錄后才能下訂單哦!
這篇文章給大家介紹WinForm中怎么設(shè)置用戶控件的按鈕事件,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
項(xiàng)目中需要對(duì)一個(gè)DataGridView控件進(jìn)行類(lèi)似于Excel查找的功能,之前是使用的DevExpress里面的DataGrid,用起來(lái)倒是很方便,它的列頭可以和Excel一樣進(jìn)行隨意的篩選,但是那個(gè)是收費(fèi)的東東,我用了幾天破解版的,擔(dān)心以后會(huì)有影響所以還是決定換掉它,Visual Studio自帶的DataGridView跟DevExpress里面的DataGrid相比確實(shí)相差太遠(yuǎn)了,樣式不好看不說(shuō),功能上也欠缺了很多,為了滿足用戶的需求只得做一個(gè)查找定位的功能出來(lái)勉強(qiáng)滿足一下用戶的需求,
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(); } //增加 一個(gè)事件,項(xiàng)目里面用到這個(gè)控件的時(shí)候就可以使用這個(gè)事件了。 [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就是用戶控件里面的查找方法,這里直接調(diào)用它并傳入一個(gè)字符串和一個(gè)DataGridView u.Find_Grid(userControlFind_OP.txtValue.Text.Trim(), this.dgv);
如果需要操作用戶控件里面其它控件,那么該控件的Modifiers屬性需要設(shè)置為Public才可以。
效果如圖:
關(guān)于WinForm中怎么設(shè)置用戶控件的按鈕事件就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。