Prevent button flatstyle from changing color behavior

leorob88

Well-known member
Joined
Dec 31, 2020
Messages
56
Programming Experience
1-3
I'm creating a form app. I'm willing to create a different theme (dark) so I made some tests for the buttons and found out it would be good to change the flatstyle to popup for the dark theme.

The dark theme is ok. The problem is if the button is disabled, when I change it back to standard, the button looks different than it normally should. It should be dark-ish grey with greyed out text, instead it becomes "clear" with a more visible text. Since I have MANY buttons to manage, I'm willing and trying to use some basic instructions and assignments.

Basically, I tried changing the backcolor as it should (225, 225, 225, not Control, otherwise it still becomes clear taking the Form backcolor) and this slightly works, meaning this involves only the border of the button and the major part has instead a brighter color than it should. Do you have an idea how I could get around this easily? In the image you can see 2 buttons as they should be and the one behaving as it shouldn't. Just to make it clear, I have about 20-30 buttons to handle, so a simple solution would be nice.

I don't think you need the code, basically I want to have the buttons in a list so I can go through the list with a "for" loop and change the properties for all buttons. The only things I'm changing are backcolor and flatstyle. As I said, i turn back to color 225, 225, 225 and not Control, or it takes the form backcolor instead of the proper basic color.
 

Attachments

  • EmdJO.png
    EmdJO.png
    1.2 KB · Views: 16
So what's wrong with recursively going through the Controls collection of the form, checking if the control is a Button, and setting the properties if the control is a Button?

As a complete aside, why are you going against the Windows UI guidelines and doing your own styling instead of using the system colors instead of the user's preferences set via the Windows settings?
 
So what's wrong with recursively going through the Controls collection of the form, checking if the control is a Button, and setting the properties if the control is a Button?

As a complete aside, why are you going against the Windows UI guidelines and doing your own styling instead of using the system colors instead of the user's preferences set via the Windows settings?
? I'm not sure i understand your question. I want to change the colors to dark and then reset them to the default. But when i do, they do not behave as they did by default.
 
My question is why are you even changing the colors? That is completely against that Windows UI guidelines. It's people not following the UI guidelines that causes people to complain that Windows is so inconsistent, and praise the Mac's consistent UI.

If the claim is that diversity is good, theb go, add to the chaos that is Windows now.. Naming conventions for classes and methods. Nah, don't do that. Diversity is good, so mix in your Java, Python, C++ style naming/coding conventions into that C# code. Why only go on green? Why not also go on red?
 
Last edited:
Anyway, the cat is out of bag. Go iterate over all the controls looking for buttons and change their colors.
 
My question is why are you even changing the colors? That is completely against that Windows UI guidelines. It's people not following the UI guidelines that causes people to complain that Windows is so inconsistent, and praise the Mac's consistent UI.

If the claim is that diversity is good, theb go, add to the chaos that is Windows now.. Naming conventions for classes and methods. Nah, don't do that. Diversity is good, so mix in your Java, Python, C++ style naming/coding conventions into that C# code. Why only go on green? Why not also go on red?
Is this even a serious answer? Don't waste my time, please.
 
Is there a quick code to reproduce the problem?
What platform is it? .Net Framework or .Net?
 
Is there a quick code to reproduce the problem?
What platform is it? .Net Framework or .Net?
.net framework. The code is simple. i have a list of buttons and i go through it with a loop.

C#:
        private void lighttheme()
        {
            for (int i = 0; i < pulsantisvuota.Count; i++)
            {
                pulsantisvuota[i].BackColor = Color.FromArgb(225, 225, 225);
                pulsanti[i].FlatStyle = FlatStyle.Standard;
            }
        }
        private void darktheme()
        {
            for (int i = 0; i < pulsantisvuota.Count; i++)
            {
                pulsantisvuota[i].BackColor = Color.FromArgb(80, 80, 80);
                pulsanti[i].FlatStyle = FlatStyle.Popup;
            }
        }
 
To reset after you have set a BackColor for a button you can set btn.UseVisualStyleBackColor = true
 
To reset after you have set a BackColor for a button you can set btn.UseVisualStyleBackColor = true
I tried it. I changed the code like this in lighttheme():

C#:
for (int i = 0; i < pulsantisvuota.Count; i++)
            {
                pulsantisvuota[i].BackColor = DefaultBackColor; //while doing some research I thought about turning back to default color
                pulsantisvuota[i].UseVisualStyleBackColor = true; //this still seems to be needed
                pulsantisvuota[i].FlatStyle = FlatStyle.Standard;
            }

So thank you very much for the help!
 

Latest posts

Back
Top Bottom