c# show a text in a label for a particular time

2019-02-19 04:23发布

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.

7条回答
甜甜的少女心
2楼-- · 2019-02-19 04:40

Make use of Timer, available in System.Timers

Run-time

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();

}

Here is demo : C# Timer Tutorial

查看更多
登录 后发表回答