Click here to Skip to main content
15,907,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can any body help me to change the back color of my text box(used to show
quantity) when the quantity became less than 5 on run time.

thanks in advance
Posted

1 solution

Hi,
try this:
C#
private void textBox2_TextChanged(object sender, EventArgs e)
{
  int quantity = 0;
  if (!Int32.TryParse(textBox2.Text, out quantity))
  {
    textBox2.BackColor = Color.Red;
    return;
  }

  if (quantity < 5)
    textBox2.BackColor = Color.Green;
  else
    textBox2.BackColor = Color.White;
}
 
Share this answer
 
v4
Comments
Abhinav S 3-Feb-11 1:08am    
As precise as possible. 5.
JF2015 3-Feb-11 1:11am    
Thanks Abhinav!
sevenbell 3-Feb-11 1:09am    
thanks its working
JF2015 3-Feb-11 1:11am    
So, please accept my answer!
sevenbell 3-Feb-11 1:13am    
i have one more doubt that is this will work when a particular textbox property is changed but how can i change the color of textbox on the time when i select product from combobox . in which event ?please replay

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900