C#遞歸遍歷窗體所有textbox控件并設(shè)置textbox事件的方法
本文實(shí)例講述了C#遞歸遍歷窗體所有textbox控件并設(shè)置textbox事件的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public virtual void SetTextBoxOnEnterStyle(object sender, EventArgs e)
{
if (sender is TextBox)
{
TextBox tbox = sender as TextBox;
if (!tbox.ReadOnly)
{
tbox.BackColor = Color.Yellow;
}
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public virtual void SetTextBoxOnLeaveStyle(object sender, EventArgs e)
{
if (sender is TextBox)
{
TextBox tbox = sender as TextBox;
if (!tbox.ReadOnly)
{
tbox.BackColor = Color.White;
}
}
}
/// <summary>
///
/// </summary>
/// <param name="frm"></param>
public virtual void SetFormTextBoxControlStyle(Form frm)
{
IterateControlsSetTextBox(frm.Controls);
}
/// <summary>
///
/// </summary>
/// <param name="ctls"></param>
public virtual void IterateControlsSetTextBox(Control.ControlCollection ctls)
{
foreach (Control control in ctls)
{
if (control is TextBox)
{
(control as TextBox).Enter += new EventHandler(SetTextBoxOnEnterStyle);
(control as TextBox).Leave += new EventHandler(SetTextBoxOnLeaveStyle);
}
if (control.Controls.Count > 0)
{
IterateControlsSetTextBox(control.Controls);
}
}
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
- C#自定義控件VS用戶控件
- C#實(shí)現(xiàn)用戶自定義控件中嵌入自己的圖標(biāo)
- C#自定義控件添加右鍵菜單的方法
- 解析C#自定義控件的制作與使用實(shí)例的詳解
- C#禁止textbox復(fù)制、粘貼、剪切及鼠標(biāo)右鍵的方法
- C#中TextBox實(shí)現(xiàn)輸入提示功能的方法
- C# TextBox 擴(kuò)展方法數(shù)據(jù)驗(yàn)證詳細(xì)說明
- C#中設(shè)置textbox限制條件的方法
- C#實(shí)現(xiàn)綁定DataGridView與TextBox之間關(guān)聯(lián)的方法
- C# TextBox控件實(shí)現(xiàn)只能輸入數(shù)字的方法
- C#與js實(shí)現(xiàn)去除textbox文本框里面重復(fù)記錄的方法
- C#自定義控件實(shí)現(xiàn)TextBox禁止粘貼的方法
相關(guān)文章
Winform界面中實(shí)現(xiàn)通用工具欄按鈕的事件處理方法
下面小編就為大家分享一篇Winform界面中實(shí)現(xiàn)通用工具欄按鈕的事件處理方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助2017-11-11C#中JavaScriptSerializer幫助類用法實(shí)例
這篇文章主要介紹了C#中JavaScriptSerializer幫助類用法,實(shí)例分析了JavaScriptSerializer幫助類處理json字符串時(shí)的技巧,需要的朋友可以參考下2014-12-12C#使用BitConverter與BitArray類進(jìn)行預(yù)定義基礎(chǔ)類型轉(zhuǎn)換
這篇文章介紹了C#使用BitConverter與BitArray類進(jìn)行預(yù)定義基礎(chǔ)類型轉(zhuǎn)換的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-05-05C#實(shí)現(xiàn)文件操作(復(fù)制,移動(dòng),刪除)的方法詳解
File類提供了常見的文件操作函數(shù),包括復(fù)制、移動(dòng)、刪除、創(chuàng)建快捷方式等,本文將通過一些簡(jiǎn)單的示例為大家詳細(xì)講講具體的使用,希望對(duì)大家有所幫助2023-05-05C#?設(shè)置Chart的X軸為時(shí)間軸???????詳情
這篇文章主要介紹了C#設(shè)置Chart的X軸為時(shí)間軸???????詳情,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08