// 0 - reserved for "not a known color"
- // "System" colors
+ // "System" colors, Part 1
ActiveBorder = 1,
ActiveCaption,
ActiveCaptionText,
WindowFrame,
WindowText,
- // "Web" Colors
+ // "Web" Colors, Part 1
Transparent,
AliceBlue,
AntiqueWhite,
Yellow,
YellowGreen,
- // New system color additions in Visual Studio 2005 (.NET Framework 2.0)
-
+ // "System" colors, Part 2
ButtonFace,
ButtonHighlight,
ButtonShadow,
GradientActiveCaption,
GradientInactiveCaption,
MenuBar,
- MenuHighlight
+ MenuHighlight,
+
+ // "Web" colors, Part 2
+ RebeccaPurple,
}
}
// All non system colors (in order of definition in the KnownColor enum).
private static readonly uint[] s_colorTable = new uint[]
{
+ // First contiguous set.
+
0x00FFFFFF, // Transparent
0xFFF0F8FF, // AliceBlue
0xFFFAEBD7, // AntiqueWhite
0xFFF5F5F5, // WhiteSmoke
0xFFFFFF00, // Yellow
0xFF9ACD32, // YellowGreen
+
+ // Second contiguous set.
+
+ 0xFF663399, // RebeccaPurple
};
internal static Color ArgbToKnownColor(uint argb)
{
if (s_colorTable[index] == argb)
{
- return Color.FromKnownColor((KnownColor)(index + (int)KnownColor.Transparent));
+ var knownColor = KnownColor.Transparent + index;
+ // Handles the mismatching of the RebeccaPurple color with ButtonFace color ("System" colors, Part 2)
+ if (knownColor > KnownColor.YellowGreen)
+ {
+ knownColor += (int)KnownColor.RebeccaPurple - (int)KnownColor.ButtonFace;
+ }
+
+ return Color.FromKnownColor(knownColor);
}
}
public static uint KnownColorToArgb(KnownColor color)
{
- Debug.Assert(color > 0 && color <= KnownColor.MenuHighlight);
+ Debug.Assert(color > 0 && color <= KnownColor.RebeccaPurple);
+
+ if (Color.IsKnownColorSystem(color))
+ {
+ return GetSystemColorArgb(color);
+ }
- return Color.IsKnownColorSystem(color)
- ? GetSystemColorArgb(color)
- : s_colorTable[(int)color - (int)KnownColor.Transparent];
+ return color < KnownColor.ButtonFace
+ ? s_colorTable[(int)color - (int)KnownColor.Transparent]
+ : s_colorTable[(int)color - (int)KnownColor.RebeccaPurple + ((int)KnownColor.YellowGreen - (int)KnownColor.WindowText)];
}
#if FEATURE_WINDOWS_SYSTEM_COLORS
public static System.Drawing.Color PowderBlue { get { throw null; } }
public static System.Drawing.Color Purple { get { throw null; } }
public byte R { get { throw null; } }
+ public static System.Drawing.Color RebeccaPurple { get { throw null; } }
public static System.Drawing.Color Red { get { throw null; } }
public static System.Drawing.Color RosyBrown { get { throw null; } }
public static System.Drawing.Color RoyalBlue { get { throw null; } }
GradientInactiveCaption = 172,
MenuBar = 173,
MenuHighlight = 174,
+ RebeccaPurple = 175,
}
[System.ComponentModel.TypeConverterAttribute("System.Drawing.PointConverter, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public partial struct Point : System.IEquatable<System.Drawing.Point>
public static Color Purple => new Color(KnownColor.Purple);
+ public static Color RebeccaPurple => new Color(KnownColor.RebeccaPurple);
+
public static Color Red => new Color(KnownColor.Red);
public static Color RosyBrown => new Color(KnownColor.RosyBrown);
public static Color Yellow => new Color(KnownColor.Yellow);
public static Color YellowGreen => new Color(KnownColor.YellowGreen);
-
//
// end "web" colors
// -------------------------------------------------------------------
public bool IsSystemColor => IsKnownColor && IsKnownColorSystem((KnownColor)knownColor);
internal static bool IsKnownColorSystem(KnownColor knownColor)
- => (knownColor <= KnownColor.WindowText) || (knownColor > KnownColor.YellowGreen);
+ => ((knownColor >= KnownColor.ActiveBorder) && (knownColor <= KnownColor.WindowText)) || ((knownColor >= KnownColor.ButtonFace) && (knownColor <= KnownColor.MenuHighlight));
// Used for the [DebuggerDisplay]. Inlining in the attribute is possible, but
// against best practices as the current project language parses the string with
public static Color FromArgb(int red, int green, int blue) => FromArgb(byte.MaxValue, red, green, blue);
public static Color FromKnownColor(KnownColor color) =>
- color <= 0 || color > KnownColor.MenuHighlight ? FromName(color.ToString()) : new Color(color);
+ color <= 0 || color > KnownColor.RebeccaPurple ? FromName(color.ToString()) : new Color(color);
public static Color FromName(string name)
{
{
internal static class KnownColorNames
{
+ // Names of all colors (in order of definition in the KnownColor enum).
private static readonly string[] s_colorNameTable = new string[]
{
+ // "System" colors, Part 1
"ActiveBorder",
"ActiveCaption",
"ActiveCaptionText",
"Window",
"WindowFrame",
"WindowText",
+
+ // "Web" Colors, Part 1
"Transparent",
"AliceBlue",
"AntiqueWhite",
"WhiteSmoke",
"Yellow",
"YellowGreen",
+
+ // "System" colors, Part 2
"ButtonFace",
"ButtonHighlight",
"ButtonShadow",
"GradientActiveCaption",
"GradientInactiveCaption",
"MenuBar",
- "MenuHighlight"
+ "MenuHighlight",
+
+ // "Web" colors, Part 2
+ "RebeccaPurple",
};
public static string KnownColorToName(KnownColor color)
{
- Debug.Assert(color > 0 && color <= KnownColor.MenuHighlight);
+ Debug.Assert(color > 0 && color <= KnownColor.RebeccaPurple);
return s_colorNameTable[unchecked((int)color) - 1];
}
}
new object[] {"Plum", 255, 221, 160, 221},
new object[] {"PowderBlue", 255, 176, 224, 230},
new object[] {"Purple", 255, 128, 0, 128},
+ new object[] {"RebeccaPurple", 255, 102, 51, 153},
new object[] {"Red", 255, 255, 0, 0},
new object[] {"RosyBrown", 255, 188, 143, 143},
new object[] {"RoyalBlue", 255, 65, 105, 225},
[Theory]
[InlineData((KnownColor)(-1))]
[InlineData((KnownColor)0)]
- [InlineData(KnownColor.MenuHighlight + 1)]
+ [InlineData(KnownColor.RebeccaPurple + 1)]
public void FromOutOfRangeKnownColor(KnownColor known)
{
Color color = Color.FromKnownColor(known);
[Theory]
[InlineData((KnownColor)(-1))]
[InlineData((KnownColor)0)]
- [InlineData(KnownColor.MenuHighlight + 1)]
+ [InlineData(KnownColor.RebeccaPurple + 1)]
public void FromOutOfRangeKnownColorToKnownColor(KnownColor known)
{
Color color = Color.FromKnownColor(known);
[Theory]
[InlineData((KnownColor)(-1))]
[InlineData((KnownColor)0)]
- [InlineData(KnownColor.MenuHighlight + 1)]
+ [InlineData(KnownColor.RebeccaPurple + 1)]
public void IsSystemColorOutOfRangeKnown(KnownColor known)
{
Color color = Color.FromKnownColor(known);
[Theory]
[InlineData((KnownColor)(-1))]
[InlineData((KnownColor)0)]
- [InlineData(KnownColor.MenuHighlight + 1)]
+ [InlineData(KnownColor.RebeccaPurple + 1)]
public void IsKnownColorOutOfRangeKnown(KnownColor known)
{
Color color = Color.FromKnownColor(known);
KnownColor.SeaShell, KnownColor.Sienna, KnownColor.Silver, KnownColor.SkyBlue, KnownColor.SlateBlue,
KnownColor.SlateGray, KnownColor.Snow, KnownColor.SpringGreen, KnownColor.SteelBlue, KnownColor.Tan,
KnownColor.Teal, KnownColor.Thistle, KnownColor.Tomato, KnownColor.Turquoise, KnownColor.Violet,
- KnownColor.Wheat, KnownColor.White, KnownColor.WhiteSmoke, KnownColor.Yellow, KnownColor.YellowGreen
+ KnownColor.Wheat, KnownColor.White, KnownColor.WhiteSmoke, KnownColor.Yellow, KnownColor.YellowGreen,
+ KnownColor.RebeccaPurple
}.Select(kc => new object[] { kc }).ToArray();
[DllImport("user32.dll", SetLastError = true)]