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 ho
From your questions, it seems you need to change the value of something like a status label to display information periodically to the user. If you are using winforms, you can use a timer and a delegate like this:
From your questions, it seems you need to change the value of something like a status label to display information periodically to the user. If you are using winforms, you can use a timer and a delegate like this:
//First create a delegate to update the label value
public delegate void labelChanger(string s);
//create timer object
Timer t = new Timer();
//create a generic List to store messages. You could also use a Queue instead.
List mod = new List();
//index for list
int cIndex = 0;
//add this in your Form Load event or after InitializeComponent()
t.Tick += (timer_tick);
t.Interval = 5000;//how long you want it to stay.
t.Start();
//the timer_tick method
private void timer_tick(object s, EventArgs e)
{
labelWarningMessage.Invoke(new labelChanger(labelWork), mod[cIndex]);
cIndex++;
}
//the method to do the actual message display
private void labelWork(string s)
{
labelWARNING.Visible = true;
labelWarningMessage.Text = "This module has a prerequisite module: " + s;
}
I hope that helps. Good Luck.
EDIT: Thought I posted this code long ago only to come back and find out I didn't...but maybe someone might find it useful.
Also, this method will be redundant in this case, since creating the Timer alone will work without the use of a delegate and is only useful for the delegate usage and UI thread access part.