首页 > 代码库 > c#递归遍历窗体所有textbox控件,然后设置textbox事件
c#递归遍历窗体所有textbox控件,然后设置textbox事件
1 /// <summary> 2 /// 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="e"></param> 6 public virtual void SetTextBoxOnEnterStyle(object sender, EventArgs e) 7 { 8 if (sender is TextBox) 9 {10 TextBox tbox = sender as TextBox;11 if (!tbox.ReadOnly)12 {13 tbox.BackColor = Color.Yellow;14 }15 }16 }17 18 /// <summary>19 /// 20 /// </summary>21 /// <param name="sender"></param>22 /// <param name="e"></param>23 public virtual void SetTextBoxOnLeaveStyle(object sender, EventArgs e)24 {25 if (sender is TextBox)26 {27 TextBox tbox = sender as TextBox;28 if (!tbox.ReadOnly)29 {30 tbox.BackColor = Color.White;31 }32 }33 }34 /// <summary>35 /// 36 /// </summary>37 /// <param name="frm"></param>38 public virtual void SetFormTextBoxControlStyle(Form frm)39 {40 IterateControlsSetTextBox(frm.Controls);41 }42 43 /// <summary>44 /// 45 /// </summary>46 /// <param name="ctls"></param>47 public virtual void IterateControlsSetTextBox(Control.ControlCollection ctls)48 {49 foreach (Control control in ctls)50 {51 if (control is TextBox)52 {53 (control as TextBox).Enter += new EventHandler(SetTextBoxOnEnterStyle);54 (control as TextBox).Leave += new EventHandler(SetTextBoxOnLeaveStyle);55 }56 57 if (control.Controls.Count > 0)58 {59 IterateControlsSetTextBox(control.Controls);60 }61 }62 }63
c#递归遍历窗体所有textbox控件,然后设置textbox事件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。