コード例 #1
0
        /// <summary>
        /// Gets the 32-bit ARGB simple color from the given hex string.
        /// </summary>
        /// <returns>The hex.</returns>
        /// <param name="hex">Hex.</param>
        public static SimpleColor FromHex(string hex)
        {
            if (hex == null)
            {
                throw new ArgumentNullException("hex");
            }
            if (hex.Length < 7)
            {
                throw new ArgumentOutOfRangeException("hex",
                                                      string.Format("The given string can never be a color: {0} too short.", hex));
            }

            if (hex.Length == 7)
            {
                return(SimpleColor.FromArgb(
                           Int32.Parse("FF" + hex.Replace("#", ""), System.Globalization.NumberStyles.HexNumber,
                                       System.Globalization.CultureInfo.InvariantCulture)));
            }
            else if (hex.Length == 9)
            {
                return(SimpleColor.FromArgb(
                           Int32.Parse(hex.Replace("#", ""), System.Globalization.NumberStyles.HexNumber,
                                       System.Globalization.CultureInfo.InvariantCulture)));
            }
            else if (hex.Length == 10)
            {
                return(SimpleColor.FromArgb(
                           Int32.Parse(hex.Replace("0x", ""), System.Globalization.NumberStyles.HexNumber,
                                       System.Globalization.CultureInfo.InvariantCulture)));
            }
            else
            {
                throw new ArgumentOutOfRangeException("hex",
                                                      string.Format("The given string can is not a hex-color: {0}.", hex));
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets the 32-bit ARGB simple color from the known color enumeration.
        /// </summary>
        /// <param name="kc"></param>
        /// <param name="alpha"></param>
        /// <returns></returns>
        public static SimpleColor FromKnownColor(KnownColor kc, int alpha)
        {
            SimpleColor knownColor = SimpleColor.FromKnownColor(kc);

            return(SimpleColor.FromArgb(alpha, knownColor.R, knownColor.G, knownColor.B));
        }
コード例 #3
0
 /// <summary>
 /// Gets the 32-bit ARGB simple color from the specified 8-bit color values (red, green, and blue). The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits.
 /// </summary>
 /// <param name="red"></param>
 /// <param name="green"></param>
 /// <param name="blue"></param>
 /// <returns></returns>
 public static SimpleColor FromArgb(int red, int green, int blue)
 {
     return(SimpleColor.FromArgb(255, red, green, blue));
 }