Saturday, June 14, 2008

Setting BackColor to System Colors (like "Control")

It took a little searching to find out how to set the BackColor or ForeColor property of a control to the predefined colors you gets in the Visual Studio Properties window for BackColor's popup color setting on the System tab. For example, I want to set to the BackColor to the "Control" color.

control.BackColor = Color.FromKnownColor(KnownColor.Control)


I found this on:

http://bytes.com/forum/thread654472.html

14 comments:

  1. In addition to setting the BackColor back to SystemColors.Control, I found that I also had to set UseVisualStyleBackColor to True to have the button again look as it did by default.

    ReplyDelete
  2. Been looking for this.
    Thanks for the info!

    ReplyDelete
  3. saved me lots of time...thanks a lot

    ReplyDelete
  4. This is great for controls like a Button or CheckBox, but controls like a TextBox or ComboBox will need Color.FromKnownColor(KnownColor.Window) (or SystemColors.Window)
    It is better to set the BackColor to Color.Empty or simply use control.ResetBackColor()

    ReplyDelete
  5. Thank you very much.

    ReplyDelete
  6. Thanks a lot friend

    ReplyDelete
  7. Thanks a lot, my friend

    ReplyDelete
  8. Thanks. My first hit on that one and got your answer right away!
    Try SystemColors.Window which does the same as shorter Term

    ReplyDelete
  9. And 8 years later, the thanks are still coming in! :)

    ReplyDelete

Note: Only a member of this blog may post a comment.