Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset to default button BackColor?

I was experimenting with different options for the button background color and ended up changing the BackColor property in the Appearance category. I then changed it back to what it is by default which is Control, but it still looks different from other buttons:

Screenshot of buttons

I've tried building the project and restarting Visual Studio, but it did not help.

I know I can just drag another button and copy/paste code, but what causes this in the first place and how do I properly fix it?

like image 491
Dennis Zaitsev Avatar asked May 13 '12 03:05

Dennis Zaitsev


People also ask

How do you change BackColor buttons?

To change the background color of the button, use the CSS background-color property and give it a value of a color of your taste. In the . button selector, you use background-color:#0a0a23; to change the background color of the button.

What is the default button color?

By default, a button has a white background and black text.

What is the default button color in android?

When I open a new android studio project, the default color for button is purple.

How do I change the color of a button in Windows?

Step 2: Drag the Button control from the ToolBox and drop it on the windows form. You are allowed to place a Button control anywhere on the windows form according to your need. Step 3: After drag and drop you will go to the properties of the Button control to set the BackColor property of the Button.


2 Answers

The BackColor property is an ambient property by default, meaning that it inherits its value from its parent control. When you set it explicitly to a particular value, that overrides the ambient nature and forces it to use that particular value.

The standard Windows button control does not support custom colors, so WinForms will actually custom draw the control to allow the designer to override its color. That way, if you want to have an ugly green or red button, you can do that.

What's happened here is you've effectively set a custom background color for the button control (you set it to the background color of a 3D control, but it could just as easily have been purple), and that's forced WinForms to custom draw the control and paint its background with your specified color. That's what gives it the "flat" appearance—the background color is now painted with a single custom color, rather than using the default gradient effect. It wouldn't have been as noticeable under the Windows Classic (pre-Aero) theme, because buttons actually were painted with the flat 3D control color. But Aero added gradients and other "hot" effects, which makes this stick out like a sore thumb.

To clear the value you've set it to and restore the ambient nature of the property, you can right-click on the property in the Properties Window, and select "Reset". You can also do it through code by setting the property to default(Color):

myButton.BackColor = default(Color); 

You will also need to set the UseVisualStyleBackColor property back to true, which gets automatically set to false whenever the BackColor property is changed to support the custom background color.

Alternatively, you can tell WinForms to ignore custom properties like that altogether and ask Windows to draw the button control. Do this by setting the FlatStyle property to FlatStyle.System.

Again, this can be done either in the designer or through code. Not only will this prevent you from altering silly things like the background color, creating a horridly ugly control, but it will also restore the native behavior of the Win32 button control to your WinForms application, including the subtle Aero fade effects on hover.

I have no idea why this was not the default. You should have to make a special request to get ugly and non-standard controls. That shouldn't just happen automatically. I can only assume it was a concession to VB 6 programmers, who have been able to make all sorts of ugly controls for years.

like image 75
Cody Gray Avatar answered Sep 21 '22 01:09

Cody Gray


When you change the default back color, it flips the UseVisualStyleBackColor property to false.

Just change that back to true and you should be set!

like image 40
pglynn Avatar answered Sep 21 '22 01:09

pglynn