Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting this timer to work in C# (newbie)
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/12755115/how-do-i-enable-this-timer-in-c">How do I enable this timer in C#?</a> </p> </blockquote> <p>Im trying to get a little project running. When I use a break point it goes through the code correctly, but when running the program at normal speed it the sequence runs too fast. Im trying to get the traffic lights sequence to change every 1 second. What is wrong with this code? Its a simple sequence of traffic lights, incase your interested :). Newbie project.</p> <pre><code> } public int counter = 0; private void rbStart_CheckedChanged(object sender, EventArgs e) { Light_timer.Start(); counter++; if (counter == 1) { pbRed.Visible = true; pbAmber.Visible = false; pbGreen.Visible = false; } else if (counter == 2) { pbRed.Visible = true; pbAmber.Visible = true; pbGreen.Visible = false; } else if (counter == 3) { pbRed.Visible = false; pbAmber.Visible = false; pbGreen.Visible = true; } else if (counter == 4) { pbRed.Visible = false; pbAmber.Visible = true; pbGreen.Visible = false; } else if (counter == 5) { pbRed.Visible = true; pbAmber.Visible = false; pbGreen.Visible = false; } else { counter = 0; } } private void rbStop_CheckedChanged(object sender, EventArgs e) { pbRed.Visible = false; pbAmber.Visible = false; pbGreen.Visible = false; } private void Form1_Load(object sender, EventArgs e) { Light_timer.Tick += new EventHandler(rbStart_CheckedChanged); Light_timer.Interval = 1000; Light_timer.Stop(); } } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload