c#中显示为特定的时间在标签的文本

问题描述:

是否有人知道如何显示在标签或在文本的特定时间的文本?假设,如果我点击一个按钮,它显示在文本框中键入的标签15秒的文本,那么就应该消失了。

Does anybody know how to show a text for a particular time in a label or in a textbox? Suppose if I clicked a button it show the text typed in the textbox in a label for 15 seconds and then it should disappear.

请在 System.Timers

运行时

Timer类代表一个Timer控件以及用于创建在运行时一个定时器。下面的代码创建在运行时一个定时器,设置其属性和事件处理程序。

Timer class represents a Timer control and used to create a Timer at run-time. The following code snippet creates a Timer at run-time, sets its property and event handler.

Timer t = new Timer();

t.Interval = 2000;

timer1.Enabled = true;

timer1.Tick += new System.EventHandler(OnTimerEvent);

这个事件处理代码看起来像下面。

The event handler code looks like following.

private void OnTimerEvent(object sender, EventArgs e)

{

    lbl.Text = DateTime.Now.ToLongTimeString() + "," + DateTime.Now.ToLongDateString();

}

下面是演示:的 C#教程定时器