c# - 如何在特定时间(例如 3 秒)内在标签上显示文本?

标签 c# time label

我有一个状态栏标签,我只想在我的状态栏标签上显示文本 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/

相关文章:

C#:如何实现和使用 NotNull 和 CanBeNull 属性

c# - 如何检测是否按下了任何键

c# - 是否可以将 Resharper Intellisense 配置为按字母顺序排序?

r - 使用 R 绘制润滑周期

asp.net-mvc-3 - 如何使用 DisplayName 属性和/或 LabelFor 在表单标签中呈现 HTML 链接?

c# - Label.Content 无法正常工作

c# - 如何在 MVVM 模式中更新模型和 View 模型?

mysql - 按小时和日期分组

java.time.format.DateTimeParseException : Unable to obtain ZonedDateTime from TemporalAccessor in format ddMMyyyyhhmmss

label - 获取torch中1000维输出张量中特定索引的ImageNet标签