【发布时间】:2022-01-21 16:58:04
【问题描述】:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Extract
{
public partial class LoadingLabel : Label
{
private int TimeToCount = 300;
private int Interval = 1000;
private System.Windows.Forms.Timer _timer;
private int counter = 0;
public LoadingLabel()
{
InitializeComponent();
this.Font = new Font("Arial", 14, FontStyle.Bold);
StartCountDownTimer(Interval, true);
}
public void StartCountDownTimer(int Interval, bool EnableTimer)
{
_timer = new System.Windows.Forms.Timer
{
Interval = Interval,
Enabled = false
};
_timer.Enabled = EnableTimer;
_timer.Tick += (sender, args) =>
{
if (counter == 0)
{
this.Text = ".";
Thread.Sleep(3);
counter++;
}
if(counter == 1)
{
this.Text = "..";
Thread.Sleep(3);
counter++;
}
if(counter == 2)
{
this.Text = "...";
Thread.Sleep(3);
counter = 0;
}
};
}
}
}
间隔设置为 1000 一秒。
我想使用间隔,所以每秒它会添加另一个点,从一个点开始到三个点。 然后在最后三个点的时候从一个重新开始。
我尝试使用 Thread.Sleep 进行测试,但它不起作用,它只显示最后三个点,仅此而已。
【问题讨论】: