0

I have one problem, i need to stop all the timers running with one button click but i can't i started with flowLayoutPanel1.Controls.Clear(); but it jut clrear the panel and the timers keep running in background.

Now my code is like this one bellow:

 private void btnClearTimersFlowPanel_Click(object sender, EventArgs e)
        {
            if (flowLayoutPanel1.Controls.Count > 0)
            {
                if (MessageBox.Show("You want to clear?", "Clear", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No)
                    return;
                else
                {
                    foreach (UC control in flowLayoutPanel1.Controls.OfType<UC>())
                    {
                        if (control is UserControl)
                        {
                            time.Timer.Stop();
                        }
                    }
                    flowLayoutPanel1.Controls.Clear();
                }
            }
            else
                return;
        }

But it just don't stop the timers i don't know what i can do to stop them, i need some help with this please.

The UC is the name of my UserControl

Mario.C
  • 65
  • 1
  • 8
  • 2
    I don't get it. You're saying you need to stop **all** the timers, yet you always stop the same one in each iteration of your loop (`time.Timer`) – Kevin Gosse Jun 17 '16 at 08:14
  • @KooKiz Because the timers have the same name, im creating 3 user controls and both are equals – Mario.C Jun 17 '16 at 08:21
  • Can you show the code where you create the timers? – Kevin Gosse Jun 17 '16 at 08:22
  • @KooKiz im using this to create the usercontrol `UC launchUser = new UC(time); flowLayoutPanel1.Controls.Add(launchUser);` and i have one loop foreach checkbox checked he will create one usercontrol – Mario.C Jun 17 '16 at 08:32
  • 1
    Should you not reference the current control you're looking at though? Like e.g. control.time.Timer.Stop(); ? – n1FF Jun 17 '16 at 08:57

0 Answers0