Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

How to Create Custom Timer Control for Multiple Textboxes?

$
0
0

Hi All,

I am trying to create my own timer control that can be used for changing the backcolor of multiple textboxes. I want to pass the txtbx to the timer when the textChanged event detects the txtbx.Text < 1000.

Timer lowAmt = new Timer();

private void LowAmountTimer(Textbox txtColorBox)
{
       lowAmt.Enabled = false;
       lowAmt.Interval = 500;

       if (txtColorBox.BackColor == Color.Gray)
               txtColorBox.BackColor = Color.Red;
       else
               txtColorBox.BackColor = Color.Gray;
}

private void textbox1_TextChanged(object sender, EventArgs e)
{
         if (Convert.ToInt32(textbox1.Text) < 1000)
         {
                      lowAmt.Start();
                      LowAmountTimer(textbox1);
         }
         else
                      lowAmt.Stop();
}

My txtbx changes to red, but not back to gray. I realized that I do not have the Tick Event implemented. Since we cannot add to the event handler parameters, how do I include the Tick event handler with what Im trying to accomplish? Im wanting a universal textbox timer control.

Thank you in advance!!!


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>