刷新一个控件
我正在尝试更改链接标签的前景色,但颜色不会以图形方式改变。
我有一个更新控件前景色的计时器
private void Timer_Tick(object sender, EventArgs e)
{
MyLbl.ForeColor = shouldUpdate? Color.Blue: Color.Gray;
}
更新成功,在调试时,我可以看到 myLbl 的前景色属性不同。那么为什么不以图形方式改变它呢?
我也尝试过
MyLbl.ForeColor = Color.Gray;
并尝试在更改前景色后添加 Application.DoEvents() 。
有什么解决办法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与普通标签不同,链接标签不以这种方式使用
ForeColor
属性来为其文本着色。使用
LinkColor
< /a> 属性代替。在您的情况下,您需要:
请注意,这不是更新问题 - 您不必显式调用 Application.DoEvents (这几乎从来都不是正确的做法)或 Invalidate 或 Refresh 来获取链接标签响应颜色变化。
Unlike vanilla labels, link-labels don't use the
ForeColor
property in this manner to colour their text.Use the
LinkColor
property instead.In your case, you need:
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.