public static bool DecodeColor(string data, out SolidColor color) { if (!string.IsNullOrEmpty(data) && !data.Equals("none", StringComparison.InvariantCultureIgnoreCase)) { Match m = WebColorRegex.Match(data); if (m.Success) { color = SolidColor.FromArgb(m.Groups[1].Value.Length > 0 ? Convert.ToByte(m.Groups[1].Value, 16) : (byte)255, Convert.ToByte(m.Groups[2].Value, 16), Convert.ToByte(m.Groups[3].Value, 16), Convert.ToByte(m.Groups[4].Value, 16)); return(true); } else { try { color = System.Drawing.Color.FromName(data); return(true); } catch { } } } color = new SolidColor(); return(false); }
public static SolidColor FromARGBValue(long value) { SolidColor c = SolidColor.FromArgb((byte)((value >> 24) & 0xff), (byte)((value >> 16) & 0xff), (byte)((value >> 8) & 0xff), (byte)((value & 0xff))); System.Diagnostics.Debug.Assert(c.A != 0); return(c); }
/// <summary> /// Create default style for grid control. /// </summary> /// <returns>Default style created</returns> public static ControlAppearanceStyle CreateDefaultControlStyle() { return(new ControlAppearanceStyle { colors = new Dictionary <ControlAppearanceColors, SolidColor> { { ControlAppearanceColors.LeadHeadNormal, SolidColor.Lavender }, { ControlAppearanceColors.LeadHeadSelected, SolidColor.Lavender }, { ControlAppearanceColors.LeadHeadIndicatorStart, SolidColor.Gainsboro }, { ControlAppearanceColors.LeadHeadIndicatorEnd, SolidColor.Silver }, { ControlAppearanceColors.ColHeadSplitter, SolidColor.LightSteelBlue }, { ControlAppearanceColors.ColHeadNormalStart, SolidColor.White }, { ControlAppearanceColors.ColHeadNormalEnd, SolidColor.Lavender }, { ControlAppearanceColors.ColHeadHoverStart, SolidColor.LightGoldenrodYellow }, { ControlAppearanceColors.ColHeadHoverEnd, SolidColor.Goldenrod }, { ControlAppearanceColors.ColHeadSelectedStart, SolidColor.LightGoldenrodYellow }, { ControlAppearanceColors.ColHeadSelectedEnd, SolidColor.Goldenrod }, { ControlAppearanceColors.ColHeadFullSelectedStart, SolidColor.WhiteSmoke }, { ControlAppearanceColors.ColHeadFullSelectedEnd, SolidColor.LemonChiffon }, { ControlAppearanceColors.ColHeadSelectedNotFocusedStart, SolidColor.LightGoldenrodYellow }, { ControlAppearanceColors.ColHeadSelectedNotFocusedEnd, SolidColor.Goldenrod }, { ControlAppearanceColors.ColHeadFullSelectedNotFocusedStart, SolidColor.WhiteSmoke }, { ControlAppearanceColors.ColHeadFullSelectedNotFocusedEnd, SolidColor.LemonChiffon }, { ControlAppearanceColors.ColHeadText, SolidColor.DarkBlue }, { ControlAppearanceColors.RowHeadSplitter, SolidColor.LightSteelBlue }, { ControlAppearanceColors.RowHeadNormal, SolidColor.AliceBlue }, { ControlAppearanceColors.RowHeadHover, SolidColor.LightSteelBlue }, { ControlAppearanceColors.RowHeadSelected, SolidColor.PaleGoldenrod }, { ControlAppearanceColors.RowHeadFullSelected, SolidColor.LemonChiffon }, { ControlAppearanceColors.RowHeadSelectedNotFocused, SolidColor.PaleGoldenrod }, { ControlAppearanceColors.RowHeadFullSelectedNotFocused, SolidColor.LemonChiffon }, { ControlAppearanceColors.RowHeadText, SolidColor.DarkBlue }, { ControlAppearanceColors.GridText, SolidColor.Black }, { ControlAppearanceColors.GridBackground, SolidColor.White }, { ControlAppearanceColors.GridLine, SolidColor.FromArgb(255, 208, 215, 229) }, { ControlAppearanceColors.SelectionBorder, ColorUtility.FromAlphaColor(180, StaticResources.SystemColor_Highlight) }, { ControlAppearanceColors.SelectionFill, ColorUtility.FromAlphaColor(50, StaticResources.SystemColor_Highlight) }, { ControlAppearanceColors.SelectionNotFocusedBorder, ColorUtility.FromAlphaColor(180, StaticResources.SystemColor_ControlDark) }, { ControlAppearanceColors.SelectionNotFocusedFill, ColorUtility.FromAlphaColor(50, StaticResources.SystemColor_ControlDark) }, { ControlAppearanceColors.OutlineButtonBorder, SolidColor.Black }, { ControlAppearanceColors.OutlinePanelBackground, StaticResources.SystemColor_Control }, { ControlAppearanceColors.OutlinePanelBorder, SolidColor.Silver }, { ControlAppearanceColors.OutlineButtonText, StaticResources.SystemColor_WindowText }, { ControlAppearanceColors.SheetTabText, StaticResources.SystemColor_WindowText }, { ControlAppearanceColors.SheetTabBorder, StaticResources.SystemColor_Highlight }, { ControlAppearanceColors.SheetTabBackground, SolidColor.White }, { ControlAppearanceColors.SheetTabSelected, StaticResources.SystemColor_Window }, }, SelectionBorderWidth = 3, }); }
public static bool DecodeColor(string data, out SolidColor color) { if (!string.IsNullOrEmpty(data) && !data.Equals("none", StringComparison.InvariantCultureIgnoreCase)) { Match m = WebColorRegex.Match(data); if (m.Success) { color = SolidColor.FromArgb(m.Groups[1].Value.Length > 0 ? Convert.ToByte(m.Groups[1].Value, 16) : (byte)255, Convert.ToByte(m.Groups[2].Value, 16), Convert.ToByte(m.Groups[3].Value, 16), Convert.ToByte(m.Groups[4].Value, 16)); return(true); } #if WINFORM || WPF || ANDROID else { try { #if WINFORM color = System.Drawing.Color.FromName(data); #elif WPF color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(data); #elif ANDROID var c = System.Drawing.Color.FromName(data); color = new SolidColor(c.R, c.G, c.B); #endif // WPF return(true); } catch { } } #endif // WINFORM || WPF } color = new SolidColor(); return(false); }
/// <summary> /// Source: http://ciintelligence.blogspot.jp/2012/02/converting-excel-theme-color-and-tint.html /// </summary> /// <param name="hslColor"></param> /// <returns></returns> public static SolidColor HSLToRgb(HSLColor hslColor) { var rgbColor = new SolidColor(); if (hslColor.S == 0) { rgbColor = SolidColor.FromArgb((byte)(hslColor.A * 255f), (byte)(hslColor.L * 255f), (byte)(hslColor.L * 255f), (byte)(hslColor.L * 255f)); return(rgbColor); } float t1; if (hslColor.L < 0.5f) { t1 = (float)(hslColor.L * (1.0f + hslColor.S)); } else { t1 = (float)(hslColor.L + hslColor.S - (hslColor.L * hslColor.S)); } float t2 = 2.0f * hslColor.L - t1; float h = hslColor.H / 360f; float tR = h + (1.0f / 3.0f); float r = SetColor(t1, t2, tR); float tG = h; float g = SetColor(t1, t2, tG); float tB = h - (1.0f / 3.0f); float b = SetColor(t1, t2, tB); rgbColor = SolidColor.FromArgb((int)(hslColor.A * 255), (int)(r * 255), (int)(g * 255), (int)(b * 255)); return(rgbColor); }