Reputation: 91
Does anyone know why my timer isn't working? Added a timer into my form. The interval is 1000.
private void button1_Click(object sender, EventArgs e)
{
label5.Visible = true;
timer2.Enabled = true;
timer2.Start();
}
private void timer2_Tick(object sender, EventArgs e)
{
if (timer2.Interval == 3000)
{
label5.Visible = false;
}
}
After 3 seconds the label is still visible, and the interval is still on 1000. What am I doing wrong?
Upvotes: 0
Views: 121
Reputation: 612954
if (timer2.Interval == 3000)
{
label5.Visible = false;
}
Since you state that the interval is 1000, the if
condition always evaluates as false
.
A timer fires at regular intervals. Specified by the Interval
property. You should set the interval to 3000
, and hide the label the first time the timer fires. When that happens you can disable the timer.
private void button1_Click(object sender, EventArgs e)
{
label5.Visible = true;
timer2.Interval = 3000;
timer2.Enabled = true;
}
private void timer2_Tick(object sender, EventArgs e)
{
label5.Visible = false;
timer2.Enabled = false;
}
Upvotes: 5