During the creation of my awesome Matching Game 😉 I found a problem that is completely out of reach.
When the player chooses two labels with symbols on them I want to lock all the other labels for 4 seconds.
But when I do that, the forecolor of all the labels changes to grey and the symbols are visible. My question is – is there a method to change the ForeColor of a disabled label in visual c#?
The project is a WinForm application.
At the moment I set the color of a label in code this way:
label1.ForeColor = lable1.BackColor;
When the user clicks the label I change it to:
lable1.ForeColor = Color.Black;
Way simpler than trying to change the way Windows draws disabled controls is to simply set a flag when you want the
Labelto be effectively “disabled”, and then check the value of that flag in yourClickevent handler method before taking whatever action you want. If the control has been “disabled”, then don’t take any action.Something like this:
Also, note that you should always use the
SystemColorsinstead of something likeColor.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.