Reputation: 303
I am new to C# and I am using windows form
.
As shown in the 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
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
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
Reputation: 1333
Try to use the System.Drawing.SystemColors
, you might find there the InactiveCaptionText
you're searching for.
Upvotes: 8