0
votes

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?

1
You are not changing timer interval in your code, It is set to 1000 and in your Timer Elapsed event you are checking if Interval is 3000. Your condition will always be falseHabib

1 Answers

5
votes
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;
}