Im using my text to numerals to text class on a form to set a timer. It needs to change my textbox to pink if it is out of range (100-10000ms) or if it is an invalid entry. It works ok with numerals but fails to work on the invalid characters or out of range characters. My first catch picks up a FormatException on entering any text and my second catch picks up ArgumentOutofRange Exception. I am a bit lost, can anyone give me some help? TIA
Code:private void tRate_TextChanged(object sender, EventArgs e) { try { tRate.BackColor = Color.White; Demo.Number = int.Parse(tRate.Text); tPeriodic.Interval = Demo.Number; tStatusMessage.Text = "Timer running at " + tPeriodic.Interval + " milliseconds"; } catch { if (tPeriodic.Interval < 100 || tPeriodic.Interval > 10000) { tRate.BackColor = Color.Pink; tPeriodic.Interval = 100; tStatusMessage.Text = "Interval out of range, using 100ms"; } } try { Demo.Text = tRate.Text; tPeriodic.Interval = Demo.Number; tStatusMessage.Text = "Timer running at " + tPeriodic.Interval + " milliseconds"; } catch { if (tPeriodic.Interval < 100 || tPeriodic.Interval > 10000) { tRate.BackColor = Color.Pink; tPeriodic.Interval = 100; tStatusMessage.Text = "Interval out of range, using 100ms"; } } //finally //{ // if (tPeriodic.Interval < 100 || tPeriodic.Interval > 10000) // { // tRate.BackColor = Color.Pink; // tPeriodic.Interval = 100; // tStatusMessage.Text = "Interval out of range, using 100ms"; // } //}



LinkBack URL
About LinkBacks


