1 /// <summary>2 /// 3 /// </summary>4 /// <param name= "Sender" ></param>5 /// <param name= "E" ></param>6 Public Virtual voidSettextboxonenterstyle (Objectsender, EventArgs e)7 {8 if(Sender isTextBox)9 {TenTextBox Tbox = Sender asTextBox; One if(!Tbox. ReadOnly) A { -Tbox. BackColor =Color.yellow; - } the } - } - - /// <summary> + /// - /// </summary> + /// <param name= "Sender" ></param> A /// <param name= "E" ></param> at Public Virtual voidSettextboxonleavestyle (Objectsender, EventArgs e) - { - if(Sender isTextBox) - { -TextBox Tbox = Sender asTextBox; - if(!Tbox. ReadOnly) in { -Tbox. BackColor =Color.White; to } + } - } the /// <summary> * /// $ /// </summary>Panax Notoginseng /// <param name= "frm" ></param> - Public Virtual voidsetformtextboxcontrolstyle (Form frm) the { + Iteratecontrolssettextbox (frm. Controls); A } the + /// <summary> - /// $ /// </summary> $ /// <param name= "CTLs" ></param> - Public Virtual voidIteratecontrolssettextbox (control.controlcollection CTLs) - { the foreach(Control controlinchCTLs) - {Wuyi if(Control isTextBox) the { -(Control asTextBox). Enter + =NewEventHandler (settextboxonenterstyle); Wu(Control asTextBox). Leave + =NewEventHandler (settextboxonleavestyle); - } About $ if(Control. Controls.Count >0) - { - Iteratecontrolssettextbox (Control. Controls); - } A } + } the
View Code
C # recursively iterates through the form all TextBox controls, and then sets the TextBox event