我怎样才能制作循环计时器?

时间:2016-03-24 19:30:56

标签: c# timer infinite-loop windows-forms-designer

我想在计时器的面板上制作时间循环标签,但是如何? 我得到了这段代码:

private void Form1_Load(object sender, EventArgs e)
{
    label3.AutoSize = true;
    label3.Text = label3.Text;
    label3.Parent = panel1;
    label3.Location = new Point(panel1.ClientSize.Width, panel1.ClientSize.Height / 2 - (label3.Height / 2));
    timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
    if (label3.Right < 0)
    {
        label3.Text = Convert.ToString(panel1.ClientSize.Width);
    }
    else
    {
        label3.Left -= 10;
    }
}

如何制作无限时间循环?

1 个答案:

答案 0 :(得分:0)

在Do ... While循环中使用StopWatch类

            Stopwatch sw = new Stopwatch();
        long time;
        sw.Start();

        do
        {
            time = sw.ElapsedMilliseconds;
        } while (time < 10000); //ten seconds