I have 4 labels, that must change to bold after waiting 500ms each.
I've tried to use this function:
LabelUpdater(lblIF); //to bold
Thread.Sleep(500);
LabelUpdater(lblIF); //to regular again
LabelUpdater(lblID); //to bold
Thread.Sleep(500);
LabelUpdater(lblID); //to regular again
private void LabelUpdater(Label labelActual)
{
if (labelActual.Font.Bold)
{
Console.WriteLine("Regular - " + DateTime.Now);
labelActual.Font = new Font(labelActual.Font, FontStyle.Regular);
}
else
{
Console.WriteLine("Bold- " + DateTime.Now);
labelActual.Font = new Font(labelActual.Font, FontStyle.Bold);
}
}
But if I try to run this program, nothing changes. If I just set to bold, everything turn bold in the end of execution.
To get working, i needed to use this:
LabelUpdater(lblIF);
Thread.Sleep(500);
Application.DoEvents(); //here
LabelUpdater(lblIF);
LabelUpdater(lblID);
Thread.Sleep(500);
Application.DoEvents(); //here
LabelUpdater(lblID);
Not sure why, i just tried and worked! :D