1
我正在嘗試在進程正在進行時爲標籤製作動畫。我希望它是這樣的(逐幀):使用計時器動畫標籤不起作用
Searching
Searching.
Searching..
Searching...
Searching
等等。我一直試圖做這種方式:
Timer _animationTimer = new Timer();
private void StartAnimation()
{
myLabel.Text = "Searching";
_animationTimer.Interval = 250;
_animationTimer.Tick += new EventHandler(this.AnimationEvent);
_animationTimer.Start();
}
private void StopAnimation()
{
_animationTimer.Stop();
}
private void AnimationEvent(object sender, EventArgs e)
{
if (!myLabel.Text.EndsWith("..."))
{
myLabel.Text += ".";
}
else
{
myLabel.Text = "Searching";
}
}
我使用這種方式:
StartAnimation();
// ... do something.
StopAnimation();
myLabel.Text = "Something";
但它不工作。它第一次運行,它完美的動畫。第二次,顯示了這個:
Searching..
Searching
Searching..
Searching
和第三次它顯示:
Searching...
Searching..
Searching.
Searching
Searching...
第四時間並不動畫的。從第五次開始經歷這個週期。
這真的很吸引我。什麼可能是錯誤的?
這絕對是原因,現在我已經修復它。非常感謝! – hattenn