【问题标题】:How can i make loop timer?我怎样才能制作循环计时器?
【发布时间】:2016-03-24 19:30:55
【问题描述】:

我想用计时器在面板中制作时间循环标签,但是怎么做? 我得到了这个代码:

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

如何进行无限时间循环?

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-09-27
      • 2013-08-18
      • 2021-06-18
      • 2019-07-13
      • 2014-05-14
      • 2023-03-23
      • 2020-08-14
      • 2012-02-27
      • 2020-08-24
      相关资源
      最近更新 更多