Click here to Skip to main content
15,846,091 members
Articles / Programming Languages / C#

Faded/Dimmed Button Images

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
15 Aug 2019CPOL 7.3K   2   5
Dim Windows Forms Buttons when disabled


I noticed that the images on my buttons aren't faded/dimmed when they're disabled. Text/back color goes darker....but not the image. Of course, I Googled a solution....and it appears that many people have the problem and there were many suggestions....but all far too complex.

Using the Code

The code is very simple.

//Define a general paint event
//This can be in a static class, a form, anywhere.
private void Ctrl_Paint(object sender, PaintEventArgs e)
    Control b = (Control)sender;
    //Paint a semi-transparent black rectangle over the button if disabled
    if (!b.Enabled)
        using (SolidBrush brdim = new SolidBrush(Color.FromArgb(128, 0, 0, 0)))
            e.Graphics.FillRectangle(brdim, e.ClipRectangle);

//Then just tie up the above to your control in a form load event:
ControlName.Paint += Ctrl_Paint;

A really simple solution - just paint a semi-transparent rectangle over the control....the amount of dimming can be altered by adjusting the alpha value (128 in the code above).

Points of Interest

You can have more than one event handler for each event. The above works by executing the Ctrl_Paint event after a control's 'normal' paint it even works on overridden events in classes.


  • 15th August, 2019: First version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

QuestionControlPaint.DrawImageDisabled? Pin
Brad_Jones16-Aug-19 7:29
Brad_Jones16-Aug-19 7:29 
AnswerRe: ControlPaint.DrawImageDisabled? Pin
AntGamble16-Sep-19 0:12
AntGamble16-Sep-19 0:12 
PraiseThank you! Pin
Member 373058716-Aug-19 3:13
Member 373058716-Aug-19 3:13 
QuestionA screenshot would help, here's why... Pin
dandy7215-Aug-19 5:22
dandy7215-Aug-19 5:22 
I haven't had to mess with manually changing the appearance of disabled buttons since the MFC days. Can you tell us more about how you're creating those buttons? As far as I'm concerned, in WinForms, they all just "do the right thing" out of the box, whether it's part of a toolbar, a menu or a regular standalone button with an image drawn on top of it.

I'm not saying you no longer have to resort to this sort of solution--I'm just curious about how you're creating those buttons since they seem to deviate from everything I've seen...

AnswerRe: A screenshot would help, here's why... Pin
AntGamble16-Sep-19 0:14
AntGamble16-Sep-19 0:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.