Link to home
Start Free TrialLog in
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




Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image

create a timer for 4 seconds and set the test to "" in the timer and kill the timer there.
Avatar of owen79
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.
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 = "";

}


ASKER CERTIFIED SOLUTION
Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of parabellum

ASKER


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