0

I have 81 RichTextBoxes in my form (Sudoku Solver), and I would like them to turn gray when user inputs data into them and when there is no data (for example ereased or never was there) to stay white. How do I manage that?

4

2 回答 2

2

Use an EventHandler!
From MSDN

private void TextChangedEventHandler(object sender, EventArgs e)
{
   TextBox tb = sender as TextBox;
   if(tb != null){
       if(tb.Text.Length > 0){
        //set color
       }
       else{
         //set color
       }
   }
}

...

//Loop through your controls (textboxes) and set handler

foreach(Control c in this.Controls){

    if(c is TextBox){
        c.TextChanged += TextChangedEventHandler;
    }

}
于 2013-06-24T09:28:29.140 回答
-2
$(".test").on("change keyup paste click", function()  {        
if(this.val()=="")

{

this.css('background-color', '#ffff00');

}

       else
      {
     this.css('background-color', '#ffff55');
 }
})
于 2013-06-24T09:32:17.603 回答