changing textbox color according to text
  • i have one percentage textbox and i want that if user write value less than 0 or greater than 100 so textbox color should be change in c#.
  • 1 Comment sorted by
  • Vote Up0Vote Down aftabaftab
    24.50 Karma Accepted Answer
    hi @ravi use textbox textchanged Event and adjust below code.


    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    try
    {
    if (textBox1.Text != "")
    {
    if (Convert.ToDecimal(textBox1.Text) < 0 || Convert.ToDecimal(textBox1.Text) > 100)
    {
    this.textBox1.BackColor = Color.Red;
    }
    else
    {
    this.textBox1.BackColor = Color.White;
    }
    }
    }
    catch
    {}
    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

Top Posters Weekly

Optimum Creative