First 27 and last 7 of System.Drawing.KnownColor are “System” colors:
for (int i = 1; i <= Enum.GetValues(typeof(KnownColor)).Length; i++){
if (i <= 27 || i >= 168){
String str = String.Format("{0}.{1}", i, (KnownColor)i);
System.Diagnostics.Trace.WriteLine(str);
}
}
1.ActiveBorder 2.ActiveCaption 3.ActiveCaptionText 4.AppWorkspace 5.Control 6.ControlDark 7.ControlDarkDark 8.ControlLight 9.ControlLightLight | 10.ControlText 11.Desktop 12.GrayText 13.Highlight 14.HighlightText 15.HotTrack 16.InactiveBorder 17.InactiveCaption 18.InactiveCaptionText | 19.Info 20.InfoText 21.Menu 22.MenuText 23.ScrollBar 24.Window 25.WindowFrame 26.WindowText 27.Transparent | 168.ButtonFace 169.ButtonHighlight 170.ButtonShadow 171.GradientActiveCaption 172.GradientInactiveCaption 173.MenuBar 174.MenuHighlight |
All KnownColors with their RGB values can be shown by the following fragment:
foreach (String c in Enum.GetNames(typeof(System.Drawing.KnownColor))){
long enumColorValue = Convert.ToInt64((KnownColor)Enum.Parse(typeof(KnownColor), c));
String str = String.Format("{0}.{1} = {2:X}",
enumColorValue, c,
System.Drawing.Color.FromName(c).ToArgb());
Trace.WriteLine(str);
}
Result looks like this:
1.ActiveBorder = FFD4D0C8
2.ActiveCaption = FFC0C0C0
3.ActiveCaptionText = FF0E1010
. . .
26.WindowText = FF000000
27.Transparent = FFFFFF
28.AliceBlue = FFF0F8FF
29.AntiqueWhite = FFFAEBD7
30.Aqua = FF00FFFF
. . .
165.WhiteSmoke = FFF5F5F5
166.Yellow = FFFFFF00
167.YellowGreen = FF9ACD32
168.ButtonFace = FFE0DFE3
169.ButtonHighlight = FFFFFFFF
. . .
172.GradientInactiveCaption = FFEEEFF7
173.MenuBar = FFE0E2EB
174.MenuHighlight = FFBBB7C7
All named-colors in KnownColors have ENUM numbers from 28 to 167.
I use LINQ to sort them by their RGB value. (will be in Part 2)
int
int
numAliceBlue = (int)KnownColor.AliceBlue,
numYellowGreen = (int)KnownColor.YellowGreen;
Dictionary<KnownColor, int> colorsRGB = new Dictionary<KnownColor, int>(numYellowGreen - numAliceBlue + 1);
for (int i = numAliceBlue; i <= numYellowGreen; i++){
KnownColor kc = (KnownColor)i;
colorsRGB.Add(kc, Color.FromKnownColor(kc).ToArgb());
}
var sortedColors = from clr in colorsRGB
orderby clr.Value descending
select clr;
foreach (KeyValuePair<KnownColor, int> clr in sortedColors){
String str = String.Format("{0:X08} - {1}", clr.Value, clr.Key);
Trace.WriteLine(str);
}
No comments:
Post a Comment