I have a CustomControl which derives from a Button. At certain points in this control's life, I want to set it's background to a special color (i.e. Plum) or a normal Control color (i'e same as the default color for other buttons). Here's the relevant code that mostly works.
public partial class MySpecialButton : Button
private void SetButtonState()
if (isSpecial && Enabled)
BackColor = Color.Plum;
BackColor = Enabled ? SystemColors.Control : SystemColors.ControlDark;
Consider these notes:
BackColor property of a
Button cause setting
false and the difference which you see between a normal button and your custom button is because of this. To solve the problem you should set
UseVisualStyleBackColor to true again, after resetting
If you don't like that border paint the button yourself or use
FlatStyle set to
Flat and use
FlatAppearance.BorderSize = 0 or any other appearance and border-size which you prefer.
The same as number one.
Foreground color of a disabled
Button is calculated based on background color. So if you reset the back ground color as described in number one, you will see no difference.