我有一个状态栏标签,我想在StatusBar标签上显示一个文本仅3秒钟
如何在不使用线程的情况下完成?
public void InfoLabel(string value)
{
if (InvokeRequired)
{
this.Invoke(new Action<string>(InfoLabel), new object[] { value });
return;
}
infoLabel.Text = value;
}
Run Code Online (Sandbox Code Playgroud)
只需在方法的末尾添加计时器:
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();
};
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5464 次 |
| 最近记录: |