C#递归遍历窗体所有textbox控件并设置textbox事件的方法

/// <summary>
///
/// </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);
 }
    }
}

上一篇:【网络编程一】主机字节序与网络字节序以及ip地址转换函数


下一篇:vim 中:wq和:wq的不同之处