using System; using System.Collections.Generic; using System.Text; using System.Drawing; namespace DevComponents.DotNetBar.Layout { internal static class ColorHelpers { /// /// Converts hex string to Color type. /// /// Hexadecimal color representation. /// Reference to Color object. public static Color GetColor(string rgbHex) { if (string.IsNullOrEmpty(rgbHex)) return Color.Empty; if (rgbHex.Length == 8) return Color.FromArgb(Convert.ToInt32(rgbHex.Substring(0, 2), 16), Convert.ToInt32(rgbHex.Substring(2, 2), 16), Convert.ToInt32(rgbHex.Substring(4, 2), 16), Convert.ToInt32(rgbHex.Substring(6, 2), 16)); return Color.FromArgb(Convert.ToInt32(rgbHex.Substring(0, 2), 16), Convert.ToInt32(rgbHex.Substring(2, 2), 16), Convert.ToInt32(rgbHex.Substring(4, 2), 16)); } /// /// Converts hex string to Color type. /// /// Color representation as 32-bit RGB value. /// Reference to Color object. public static Color GetColor(int rgb) { if (rgb == -1) return Color.Empty; return Color.FromArgb((rgb & 0xFF0000) >> 16, (rgb & 0xFF00) >> 8, rgb & 0xFF); } /// /// Converts hex string to Color type. /// /// Color representation as 32-bit RGB value. /// Reference to Color object. public static Color GetColor(int alpha, int rgb) { if (rgb == -1) return Color.Empty; return Color.FromArgb(alpha, (rgb & 0xFF0000) >> 16, (rgb & 0xFF00) >> 8, rgb & 0xFF); } public static string ToArgbString(Color color) { if (color.IsEmpty) return ""; if (color.A == 255) return color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2"); return color.A.ToString("X2") + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2"); } } }