Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 1.14 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Can this code be simplified?
  2. if (textBox_naam.Text.Length < 3)
  3. {
  4.    textBox_naam.BackColor = Color.FromArgb(205, 92, 92);
  5. }
  6. else
  7. {
  8.    textBox_naam.BackColor = Color.White;
  9. }
  10.  
  11. if (textBox_email.Text.Length < 5)
  12. {
  13.    textBox_email.BackColor = Color.FromArgb(205, 92, 92);
  14. }
  15. else
  16. {
  17.    textBox_email.BackColor = Color.White;
  18. }
  19.  
  20. if (textBox_body.Text.Length < 20)
  21. {
  22.    textBox_body.BackColor = Color.FromArgb(205, 92, 92);
  23. }
  24. else
  25. {
  26.    textBox_body.BackColor = Color.White;
  27. }
  28.        
  29. SetBackColor(textBox_naam, 3, GOOD_COLOR, BAD_COLOR);
  30. SetBackColor(textBox_email, 5, GOOD_COLOR, BAD_COLOR);
  31. SetBackColor(textBox_body, 20, GOOD_COLOR, BAD_COLOR);
  32.        
  33. public void SetBackColor(TextBox tb, int minLength, Color goodColor, Color badColor)
  34. {
  35.     tb.BackColor = tb.Text.Length < minLength ? badColor : goodColor;
  36. }
  37.        
  38. textBox_naam.BackColor = textBox_naam.Text.Length < 3 ? Color.FromArgb(205, 92, 92) : Color.White;
  39.        
  40. Color other=Color.FromArgb(205,92,92);
  41. textBox_naam.BackColor=(textBox_naam.Text.Length<3?other:Color.White);
  42. textBox_email.BackColor=(textBox_email.Text.Length<5?other:Color.White);
  43. textBox_body.BackColor=(textBox_body.Text.Length<20?other:Color.White);