我有一个问题,我需要停止所有计时器运行时只需点击一下按钮,但我可以使用flowLayoutPanel1.Controls.Clear();
开始,但它突然显示面板并且计时器继续在后台运行。
现在我的代码就像下面这样:
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;
}
但它不会阻止定时器,我不知道我能做些什么来制止它们,我需要一些帮助。
UC
是我的UserControl的名称