如何在标签上显示特定时间(如3秒)的文本?

Mur*_*sli 1 c# time label

我有一个状态栏标签,我想在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)

Mar*_*cin 6

只需在方法的末尾添加计时器:

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)