コード例 #1
0
 /// <summary>
 /// Saves RGB value into the classes.
 /// Given 1 parameter string hex value (#ff0000) (preceding with #), or
 /// Given 1 parameter string color code(white, black, orange...)
 /// </summary>
 /// <param name="color">The color.</param>
 public BCGColor(string color)
 {
     if (!string.IsNullOrEmpty(color))
     {
         if (color.Length == 7 && color.StartsWith("#", StringComparison.Ordinal))
         {
             this.vR = Int16.Parse(color.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier, CultureInfo.CurrentCulture);
             this.vG = Int16.Parse(color.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier, CultureInfo.CurrentCulture);
             this.vB = Int16.Parse(color.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier, CultureInfo.CurrentCulture);
         }
         else
         {
             ParseHex(BCGColor.GetColor(color));
         }
     }
     else
     {
         ParseHex(0);
     }
 }
コード例 #2
0
 /// <summary>
 /// Returns class of <see cref="BCGColor"/> depending of the string color.
 ///
 /// If the color doens't exist, it defaults to <paramref name="defaultColor"/>.
 /// </summary>
 /// <param name="color">The color name.</param>
 /// <param name="defaultColor">The default color name.</param>
 /// <returns>The color.</returns>
 public static int GetColor(string color, string defaultColor)
 {
     return((color.ToLower(CultureInfo.CurrentCulture)) switch
     {
         "" or "white" => 0xffffff,
         "black" => 0x000000,
         "maroon" => 0x800000,
         "red" => 0xff0000,
         "orange" => 0xffa500,
         "yellow" => 0xffff00,
         "olive" => 0x808000,
         "purple" => 0x800080,
         "fuchsia" => 0xff00ff,
         "lime" => 0x00ff00,
         "green" => 0x008000,
         "navy" => 0x000080,
         "blue" => 0x0000ff,
         "aqua" => 0x00ffff,
         "teal" => 0x008080,
         "silver" => 0xc0c0c0,
         "gray" => 0x808080,
         _ => BCGColor.GetColor(defaultColor, "white"),
     });
コード例 #3
0
 /// <summary>
 /// Returns class of <see cref="BCGColor"/> depending of the string color.
 ///
 /// If the color doens't exist, it defaults to white.
 /// </summary>
 /// <param name="color">The color name.</param>
 /// <returns>The color.</returns>
 public static int GetColor(string color)
 {
     return(BCGColor.GetColor(color, "white"));
 }