Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8467991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:48:22+00:00 2026-06-10T15:48:22+00:00

I have the following method which works fine: button21.FlatAppearance.BorderSize = 0; button21.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;

  • 0

I have the following method which works fine:

button21.FlatAppearance.BorderSize = 0;
button21.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;

As you can see, I have many buttons (~30), so instead of applying style on every button – why not apply on all of them at once on Form_Load event? So I wrote this method:

public void ChangeButtonStyles()
{
    foreach (Control con in this.Controls)
    {
        if (con is Button)
        {
            Button but = con as Button;
            but.FlatAppearance.BorderSize = 0;
            but.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
        }
    }
}

But it’s not working because when you hover a mouse on a button – you can see background change, which proves that but.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent; is not working

Why isn’t the code working?

public Form1()
{
    InitializeComponent();

  // works
    //button21.FlatAppearance.BorderSize = 0;
    //button21.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;

  // doesn't work
    ChangeButtonStyles();
}

EDIT: Solution

public void ChangeButtonStyles()
{
    foreach (Control con in this.Controls)
    {
        if (con is Button)
        {
            Button but = con as Button;
            but.FlatAppearance.BorderSize = 0;
            but.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
        }
        if (con is GroupBox)
        {
            foreach (Control subcon in con.Controls)
            {
                if (subcon is Button)
                {
                    Button but = subcon as Button;
                    but.FlatAppearance.BorderSize = 0;
                    but.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
                }
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:48:24+00:00Added an answer on June 10, 2026 at 3:48 pm

    Have you tried debugging the code to see if it actually gets executed? this.Controls will return the top level controls. If the buttons are nested inside other controls you need to be more recursive.

    public void ChangeButtonStyles(Control source)
    {
        foreach (Control con in source.Controls)
        {
            if (con is Button)
            {
                Button but = con as Button;
                but.FlatAppearance.BorderSize = 0;
                but.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
            }
            else
            {
                ChangeButtonStyles(con);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following issue.I have a camera with lookAt method which works fine.I
I have the following code which works just fine when the method is POST,
I have the following code to retrieve a file using FTP (which works fine).
I have the following code, which works fine if you just want to populate
I have following code which works fine, however when I updated to Lion I
I have the following so far which works fine. Im sure there is probably
I have the following regex pattern which works fine: #^(.+?)=(.+?)$#D However I want to
I have the following function which works fine when tied to an onClick() event..
I have the following code, which works fine in FF, but the .append() function
I have following method which I am using to load ActiveX control dynamically, Dim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.