禁用控制文本颜色 - 怎么改 [英] Text color of disabled control - how to change it

查看:244
本文介绍了禁用控制文本颜色 - 怎么改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的创作真棒配对游戏的过程中,)我发现了一个问题,那就是完全地遥不可及。

during the creation of my awesome Matching Game ;) I found a problem that is completly out of reach.

当玩家选择与他们的符号两个标签,我想锁定所有其他标签,持续4秒。

When player choose two labels with symbols on them i want to lock all other labels for 4 seconds.

但是,当我做到这一点,所有标签的​​前景色变为灰色,且符号是可见的。我的问题是 - ?有没有梅托德改变前景色 Visual C#中禁用的标签

But when I do that, the forecolor of all labels change to grey and symbols are visible. My question is - is there a metod to change the ForeColor of disabled label in visual c#?

该项目是一个WinForm aplication

The project is a WinForm aplication

目前,我在$ C $设置标签的颜色为c这样      label1.ForeColor = lable1.BackColor; 当用户点击标签,我把它改为      lable1.ForeColor = Color.Black;

At the moment I set the color of label in code this way label1.ForeColor = lable1.BackColor; And when user click label I change it to lable1.ForeColor = Color.Black;

推荐答案

方式的不是试图更改Windows绘制禁用的控件,您只需设置一个标志,当你想要的<$ C $的方式更简单C>标签来有效地已禁用,然后检查该标志的值的点击事件处理方法采取任何行动,你想之前。如果控制已被禁用,然后不采取任何行动。

Way simpler than trying to change the way Windows draws disabled controls is to simply set a flag when you want the Label to be effectively "disabled", and then check the value of that flag in your Click event handler method before taking whatever action you want. If the control has been "disabled", then don't take any action.

事情是这样的:

private bool labelDisabled = false;

private void myLabel_Click(object sender, EventArgs e)
{
    if (!labelDisabled)
    {
        this.ForeColor = SystemColors.ControlText;
    }
}

另外请注意,您应该始终使用 systemColors中,而不是像 Col​​or.Black
如果你硬code特定的颜色值,他们会在用户定制自己的默认Windows主题经常发生冲突。 雷蒙德陈讨论这样做的危险在他的博客上的文章。

Also, note that you should always use the SystemColors instead of something like Color.Black.
If you hard-code specific color values, they will often conflict when the user customizes their default Windows theme. Raymond Chen discusses the perils of this in an article on his blog.

这篇关于禁用控制文本颜色 - 怎么改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆