Sam
Sam

Reputation: 303

How to access System colour list in windows form c#

I am new to C# and I am using windows form.

As shown in the screenshot

screenshot

To change button backColour using code you do this:

 button_1.BackColor = Color.Red;

Using this code I can only select any colour from the Web list but I can not find a colour which is listed in the System section. For Example I can not find the "InactiveCaptionText" colour programmatically.

Anyone knows how to change button backColour to a colour from the System list using code?

Upvotes: 4

Views: 3129

Answers (3)

Jevgenij Kononov
Jevgenij Kononov

Reputation: 1239

Why not to use RGB color...or hex function and create your own color.

private Color RgbExample()
{
    // Create a green color using the FromRgb static method.
    Color myRgbColor = new Color();
    myRgbColor = Color.FromRgb(0, 255, 0);
    return myRgbColor;
}
To get all colors 

List<System.Windows.Media.Color> listOfMediaColours = new List<System.Windows.Media.Color>();
foreach(KnownColor color in Enum.GetValues(typeof(KnownColor)))
{
    System.Drawing.Color col = System.Drawing.Color.FromKnownColor(color);
    listOfMediaColours.Add(System.Windows.Media.Color.FromArgb(col.A, col.R, col.G, col.B));
}

Hex way to get color

using System.Windows.Media;

Color color = (Color)ColorConverter.ConvertFromString("#FFDFD991");

Upvotes: 1

Niranjan Singh
Niranjan Singh

Reputation: 18290

You are looking for SystemColors.InactiveCaptionText Property which returns a Color structure that is the color of the text in an inactive window's title bar.and use as below:

using System.Drawing;
//Method call
button_1.BackColor = SystemColors.InactiveCaptionText;

Upvotes: 3

Gonzo345
Gonzo345

Reputation: 1333

Try to use the System.Drawing.SystemColors, you might find there the InactiveCaptionText you're searching for.

Upvotes: 8

Related Questions