How to avoid color changes when button is disabled
-
-
Hi, We have a Windows Forms project with quite a few flatstyle buttons. When we disable the buttons, the colors of the buttons are changed automatically :( Is it possible to override this somehow, so we can control the colors ourselves? Thanks, Karl
You could create your own buttons, the simplest way is to inherit from Button and override some functions:
public class BernieButton : Button
{
protected override void OnEnabledChanged(EventArgs e)
{
base.OnEnabledChanged(e);
// handle the color properties here
....
}
} -
Hi, We have a Windows Forms project with quite a few flatstyle buttons. When we disable the buttons, the colors of the buttons are changed automatically :( Is it possible to override this somehow, so we can control the colors ourselves? Thanks, Karl
Yeah, that's the expected behavior. It's the standard notification to the user that the button will no longer work in the current situation. Why would you want to change this?? If you don't change the color, the user will wonder what's wrong with your app because they think they're clicking on an active button and nothing is happening!
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Hi, We have a Windows Forms project with quite a few flatstyle buttons. When we disable the buttons, the colors of the buttons are changed automatically :( Is it possible to override this somehow, so we can control the colors ourselves? Thanks, Karl
In fact the BackColor of control doesn't change and only ForeColor and BorderColor change. Set FlatStyle to Flat, Set a non system BorderColor in FlatAppearance, Set a non system BackColor and you will see background and border will not change. Only ForeColor changes to show difference of enabled and disabled button.