Search code examples
c#winformsdelay

How can I update the value of a Label control periodically?


I'm trying to make a label display some text, and then after a short while refresh itself and be able to re-display something else later. At the moment however I don't know how to make a label pause (if at all possible).

My code so far:

foreach (var x in mod)
{
      labelWARNING.Visible = true;
      labelWarningMessage.Text = "This module has a prerequisite module: " + x;
      //need a pause here to give user sufficient time to read the above text
      //labelWarningMessage.Text = "";
}

Solution

  • I used a timer.

    private void timer1_Tick(object sender, EventArgs e)
    {        
          labelWarningMessage.Text = "";
          labelWARNING.Visible = false;
    }