C # recursively traverse all textbox controls in the form, and then set the textbox event,

Source: Internet
Author: User

C # recursively traverse all textbox controls in the form, and then set the textbox event,
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} 63View Code

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.