Question

I am trying to change a link label's fore color but the color won't graphically change.

I have a timer that updates the fore color of the control

private void Timer_Tick(object sender, EventArgs e)
    {
        MyLbl.ForeColor = shouldUpdate? Color.Blue: Color.Gray;
    }

The update is successful and while debugging, I can see that the fore color property of myLbl is different. So why doesn't it change it graphically?

I also tried

MyLbl.ForeColor = Color.Gray;

And tried adding Application.DoEvents() after the change of the fore color.

Any solutions?

Was it helpful?

Solution

Unlike vanilla labels, link-labels don't use the ForeColor property in this manner to colour their text.

Use the LinkColor property instead.

Gets or sets the color used when displaying a normal link.

In your case, you need:

MyLbl.LinkColor = shouldUpdate? Color.Blue: Color.Gray;

Note that this not an update problem - you don't have to explicitly call Application.DoEvents (which is almost never the right thing to do) or Invalidate or Refresh to get the link-label to respond to the colour-change.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top