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用戶(hù)控件
- C#實(shí)現(xiàn)用戶(hù)自定義控件中嵌入自己的圖標(biāo)
- C#自定義控件添加右鍵菜單的方法
- 解析C#自定義控件的制作與使用實(shí)例的詳解
- C#禁止textbox復(fù)制、粘貼、剪切及鼠標(biāo)右鍵的方法
- C#中TextBox實(shí)現(xiàn)輸入提示功能的方法
- C# TextBox 擴(kuò)展方法數(shù)據(jù)驗(yàn)證詳細(xì)說(shuō)明
- 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)文章
簡(jiǎn)單掌握Windows中C#啟動(dòng)外部程序進(jìn)程的方法
這篇文章主要介紹了Windows中C#啟動(dòng)外部程序進(jìn)程的方法,例子中同時(shí)包括了進(jìn)程關(guān)閉的方法,需要的朋友可以參考下2016-03-03
細(xì)說(shuō)C#中的枚舉:轉(zhuǎn)換、標(biāo)志和屬性
枚舉是 C# 中最有意思的一部分,大部分開(kāi)發(fā)人員只了解其中的一小部分,甚至網(wǎng)上絕大多數(shù)的教程也只講解了枚舉的一部分。那么,我將通過(guò)這篇文章向大家具體講解一下枚舉的知識(shí),需要的朋友可以參考下2020-02-02
深入學(xué)習(xí)C#網(wǎng)絡(luò)編程之HTTP應(yīng)用編程(下)
這篇文章主要介紹了深入學(xué)習(xí)C#網(wǎng)絡(luò)編程之HTTP應(yīng)用編程的相關(guān)知識(shí),文中講解的非常詳細(xì),幫助大家更好的學(xué)習(xí)c#網(wǎng)絡(luò)編程,感興趣的朋友可以了解下2020-06-06
C#中Monitor對(duì)象與Lock關(guān)鍵字的區(qū)別分析
這篇文章主要介紹了C#中Monitor對(duì)象與Lock關(guān)鍵字的區(qū)別,需要的朋友可以參考下2013-06-06
C#使用smtp發(fā)送帶附件的郵件實(shí)現(xiàn)方法
這篇文章主要介紹了C#使用smtp發(fā)送帶附件的郵件實(shí)現(xiàn)方法,可直接將string類(lèi)型結(jié)果保存為附件,實(shí)例中備有相應(yīng)的注釋便于理解,需要的朋友可以參考下2014-11-11

