我有一个状态栏标签,我只想在我的状态栏标签上显示文本 3 秒
不使用线程怎么办?
public void InfoLabel(string value)
{
if (InvokeRequired)
{
this.Invoke(new Action<string>(InfoLabel), new object[] { value });
return;
}
infoLabel.Text = value;
}
最佳答案
只需在方法的末尾添加计时器即可:
if (!string.IsNullOrWhiteSpace(value))
{
System.Timers.Timer timer = new System.Timers.Timer(3000) { Enabled = true };
timer.Elapsed += (sender, args) =>
{
this.InfoLabel(string.Empty);
timer.Dispose();
};
}
关于c# - 如何在特定时间(例如 3 秒)内在标签上显示文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9414052/