public static Pen FromSystemColor(Color c) { if (!ColorUtil.IsSystemColor(c)) { throw new ArgumentException(SR.Format(SR.ColorNotSystemColor, c.ToString())); } Pen[] systemPens = (Pen[])SafeNativeMethods.Gdip.ThreadData[s_systemPensKey]; if (systemPens == null) { systemPens = new Pen[(int)KnownColor.WindowText + (int)KnownColor.MenuHighlight - (int)KnownColor.YellowGreen]; SafeNativeMethods.Gdip.ThreadData[s_systemPensKey] = systemPens; } int idx = (int)c.ToKnownColor(); if (idx > (int)KnownColor.YellowGreen) { idx -= (int)KnownColor.YellowGreen - (int)KnownColor.WindowText; } idx--; Debug.Assert(idx >= 0 && idx < systemPens.Length, "System colors have been added but our system color array has not been expanded."); if (systemPens[idx] == null) { systemPens[idx] = new Pen(c, true); } return(systemPens[idx]); }
public static Pen FromSystemColor(Color c) { if (ColorUtil.IsSystemColor(c)) { Pen newPen = new Pen(c); newPen.isModifiable = false; return(newPen); } String message = String.Format("The color {0} is not a system color.", c); throw new ArgumentException(message); }
public static Color ArgbToKnownColor(int targetARGB) { EnsureColorTable(); for (int index = 0; index < s_colorTable.Length; ++index) { int argb = s_colorTable[index]; if (argb == targetARGB) { Color color = ColorUtil.FromKnownColor((KnownColor)index); if (!ColorUtil.IsSystemColor(color)) { return(color); } } } return(Color.FromArgb(targetARGB)); }
public SolidBrush(Color color) { _color = color; IntPtr nativeBrush = IntPtr.Zero; int status = SafeNativeMethods.Gdip.GdipCreateSolidFill(_color.ToArgb(), out nativeBrush); SafeNativeMethods.Gdip.CheckStatus(status); SetNativeBrushInternal(nativeBrush); #if FEATURE_SYSTEM_EVENTS if (ColorUtil.IsSystemColor(_color)) { SystemColorTracker.Add(this); } #endif }
/// <summary> /// Translates the specified <see cref='Color'/> to an Html string color representation. /// </summary> public static string ToHtml(Color c) { string colorString = string.Empty; if (c.IsEmpty) { return(colorString); } if (ColorUtil.IsSystemColor(c)) { switch (c.ToKnownColor()) { case KnownColor.ActiveBorder: colorString = "activeborder"; break; case KnownColor.GradientActiveCaption: case KnownColor.ActiveCaption: colorString = "activecaption"; break; case KnownColor.AppWorkspace: colorString = "appworkspace"; break; case KnownColor.Desktop: colorString = "background"; break; case KnownColor.Control: colorString = "buttonface"; break; case KnownColor.ControlLight: colorString = "buttonface"; break; case KnownColor.ControlDark: colorString = "buttonshadow"; break; case KnownColor.ControlText: colorString = "buttontext"; break; case KnownColor.ActiveCaptionText: colorString = "captiontext"; break; case KnownColor.GrayText: colorString = "graytext"; break; case KnownColor.HotTrack: case KnownColor.Highlight: colorString = "highlight"; break; case KnownColor.MenuHighlight: case KnownColor.HighlightText: colorString = "highlighttext"; break; case KnownColor.InactiveBorder: colorString = "inactiveborder"; break; case KnownColor.GradientInactiveCaption: case KnownColor.InactiveCaption: colorString = "inactivecaption"; break; case KnownColor.InactiveCaptionText: colorString = "inactivecaptiontext"; break; case KnownColor.Info: colorString = "infobackground"; break; case KnownColor.InfoText: colorString = "infotext"; break; case KnownColor.MenuBar: case KnownColor.Menu: colorString = "menu"; break; case KnownColor.MenuText: colorString = "menutext"; break; case KnownColor.ScrollBar: colorString = "scrollbar"; break; case KnownColor.ControlDarkDark: colorString = "threeddarkshadow"; break; case KnownColor.ControlLightLight: colorString = "buttonhighlight"; break; case KnownColor.Window: colorString = "window"; break; case KnownColor.WindowFrame: colorString = "windowframe"; break; case KnownColor.WindowText: colorString = "windowtext"; break; } } else if (c.IsNamedColor) { if (c == Color.LightGray) { // special case due to mismatch between Html and enum spelling colorString = "LightGrey"; } else { colorString = c.Name; } } else { colorString = "#" + c.R.ToString("X2", null) + c.G.ToString("X2", null) + c.B.ToString("X2", null); } return(colorString); }
public static string ToHtml(Color c) { if (c.IsEmpty) { return(String.Empty); } if (ColorUtil.IsSystemColor(c)) { KnownColor kc = c.ToKnownColor(); switch (kc) { case KnownColor.ActiveBorder: case KnownColor.ActiveCaption: case KnownColor.AppWorkspace: case KnownColor.GrayText: case KnownColor.Highlight: case KnownColor.HighlightText: case KnownColor.InactiveBorder: case KnownColor.InactiveCaption: case KnownColor.InactiveCaptionText: case KnownColor.InfoText: case KnownColor.Menu: case KnownColor.MenuText: case KnownColor.ScrollBar: case KnownColor.Window: case KnownColor.WindowFrame: case KnownColor.WindowText: return(KnownColors.GetName(kc).ToLowerInvariant()); case KnownColor.ActiveCaptionText: return("captiontext"); case KnownColor.Control: return("buttonface"); case KnownColor.ControlDark: return("buttonshadow"); case KnownColor.ControlDarkDark: return("threeddarkshadow"); case KnownColor.ControlLight: return("buttonface"); case KnownColor.ControlLightLight: return("buttonhighlight"); case KnownColor.ControlText: return("buttontext"); case KnownColor.Desktop: return("background"); case KnownColor.HotTrack: return("highlight"); case KnownColor.Info: return("infobackground"); default: return(String.Empty); } } if (c.IsNamedColor) { if (c == Color.LightGray) { return("LightGrey"); } else { return(c.Name); } } return(FormatHtml(c.R, c.G, c.B)); }