简体   繁体   中英

C# Button Background Color

i have a Windows Form, and i want make a modern design.
I'm just having a problem with button styling, you can help-me?

I want to remove or hide the background color when the button was clicked, I managed to remove the background color from when the mouse is over the component with the following code:

FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;

Now i need remove or hide this (grey background):
Form Picture

How i make this?

Thank you!

I obtained the solution with many attempts.
Just change the FlatAppearance.MouseOverBackColor and FlatAppearance.MouseDownBackColor to the background color of the Form or the item it is attached to.

Example: You have a form with a panel, the color of the panel is red, so set the attributes to red, or just put "Color.Transparent"

buttonName.FlatAppearance.MouseOverBackColor = Color.FromArg(255, 0, 0) // red;
buttonName.FlatAppearance.MouseDownBackColor = Color.Transparent; // same result

So, if you have a class that extends the Button object, just make code like this:

public class MyButton : Button
{
        public MyButton()
        {
            FlatAppearance.MouseOverBackColor = Color.Transparent; // or Color.[Preference]
            FlatAppearance.MouseDownBackColor = Color.Transparent; // or Color.[Preference]
        }

        // Rest of your code...
}

Otherwise, do a foreach, as below

foreach (var button in this.Controls.OfType<Button>())
{
         button.FlatAppearance.MouseOverBackColor = Color.Transparent; // or Color.[Preference]
         button.FlatAppearance.MouseDownBackColor = Color.Transparent; // or Color.[Preference]
}

The codes above are examples for everyone to be able to build their own logic, if in doubt I can help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM