
Untitled
By: a guest on
Jul 31st, 2012 | syntax:
None | size: 1.14 KB | hits: 12 | expires: Never
Can this code be simplified?
if (textBox_naam.Text.Length < 3)
{
textBox_naam.BackColor = Color.FromArgb(205, 92, 92);
}
else
{
textBox_naam.BackColor = Color.White;
}
if (textBox_email.Text.Length < 5)
{
textBox_email.BackColor = Color.FromArgb(205, 92, 92);
}
else
{
textBox_email.BackColor = Color.White;
}
if (textBox_body.Text.Length < 20)
{
textBox_body.BackColor = Color.FromArgb(205, 92, 92);
}
else
{
textBox_body.BackColor = Color.White;
}
SetBackColor(textBox_naam, 3, GOOD_COLOR, BAD_COLOR);
SetBackColor(textBox_email, 5, GOOD_COLOR, BAD_COLOR);
SetBackColor(textBox_body, 20, GOOD_COLOR, BAD_COLOR);
public void SetBackColor(TextBox tb, int minLength, Color goodColor, Color badColor)
{
tb.BackColor = tb.Text.Length < minLength ? badColor : goodColor;
}
textBox_naam.BackColor = textBox_naam.Text.Length < 3 ? Color.FromArgb(205, 92, 92) : Color.White;
Color other=Color.FromArgb(205,92,92);
textBox_naam.BackColor=(textBox_naam.Text.Length<3?other:Color.White);
textBox_email.BackColor=(textBox_email.Text.Length<5?other:Color.White);
textBox_body.BackColor=(textBox_body.Text.Length<20?other:Color.White);