Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text color of disabled control - how to change it

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;
like image 333
Mqati Avatar asked May 14 '11 14:05

Mqati


1 Answers

Just create your own label with a redefined paint event:

protected override void OnPaint ( System.Windows.Forms.PaintEventArgs e )
{
    if ( Enabled )
    {
        //use normal realization
        base.OnPaint (e);
        return;
    }
    //custom drawing
    using ( Brush aBrush = new SolidBrush( "YourCustomDisableColor" ) )
    {
        e.Graphics.DrawString( Text, Font, aBrush, ClientRectangle );
    }
}

Be careful with text format flags during text drawing.

like image 144
Allender Avatar answered Sep 22 '22 03:09

Allender