c#中显示为特定的时间在标签的文本 [英] c# show a text in a label for a particular time
本文介绍了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#教程定时器
这篇关于c#中显示为特定的时间在标签的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文