Avatar of parabellum
parabellum
 asked on

Make label text disappear after a fixed duration


Hello,
I am using c#, VS 2008 and winforms.
I have label named lblResult.
When the user clicks a button, i  am showing the operation result  on lblResult.Text.
After i set lblResult.Text, i want to reset the text to "" , after 4 seconds. How can i do that?

thanks




.NET ProgrammingC#

Avatar of undefined
Last Comment
parabellum

8/22/2022 - Mon
Roshan Davis

create a timer for 4 seconds and set the test to "" in the timer and kill the timer there.
owen79

Two options Thread.Sleep(4000) but that will stop the UI thread and your user can't do anything.

or create a timer for the 4 seconds and sort out the "" during the tick event.
vora_bhaumik

Try the below code,

protected void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
test = 1;

timer1.Interval = 4000;
timer1.Start();

timer1.Enabled = true;

}



private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{



lblCounter.Text = "";

}


Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Roshan Davis

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
parabellum

ASKER

I was using Timer. But my problem was to run it only once.
roshmon solved this problem.
Thank you all.