Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. How to avoid color changes when button is disabled

How to avoid color changes when button is disabled

Scheduled Pinned Locked Moved Windows Forms
winformstutorialquestion
4 Posts 4 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Ksmart12
    wrote on last edited by
    #1

    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

    B D X 3 Replies Last reply
    0
    • K Ksmart12

      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

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      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
      ....
      }
      }

      1 Reply Last reply
      0
      • K Ksmart12

        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

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • K Ksmart12

          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

          X Offline
          X Offline
          xstoneheartx
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups