1 Replies - 672 Views - Last Post: 21 June 2016 - 08:53 PM Rate Topic: -----

#1 D3N   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-August 14

Getting a Color Value from a ComboBox

Posted 21 June 2016 - 05:58 PM

Hi everyone, i do have a problem since last night. I am trying to pass a value from a combobox which contains some color values like "BLUE", "CYAN", "RED" and so on. I hope you don't mind if i will try to paste some code here as this is a third party product hoping you can help me out of here.

I have an object SOLIDBRUSH which accepts a color parameter like
SolidBrush(Color.Aqua)
so.
So what i am trying to do now is to pass my combobox value like this
SolidBrush(combobox1.selectedItem)


To better understand my situation, let me post what the SolidBrush class contains, and what the Color class contains as well

SOLIDBRUSH CLASS
// ===========================================================================
//	2013 WebSupergoo. All rights reserved.
// ===========================================================================

using System;
using WebSupergoo.ABCpdf10.Drawing;

namespace WebSupergoo.ABCpdf10.Drawing
{
	public interface Brush
    {
        Color Color { get; set; }
		
		}
	}
	
	#region SolidBrush
	/// <summary>
	/// Used to fill the interiors of graphical shapes such as rectangles, ellipses, pies, polygons, and paths.
	/// </summary>
	public sealed class SolidBrush : Brush {
		#region Declare variables
		Color _color;
	   
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the color of this Brush object.  
		/// </summary>
		public Color Color {
			get { return _color; }
			set { _color = value; }
		}
		#endregion

		#region Constructors
		/// <summary>
		/// Initializes a new instance of the Brush class with 
		/// the specified Color property.
		/// </summary>
		/// <param name="color">The color of this System.Drawing.Pen object.</param>
		public SolidBrush(Color color) {
			_color = color;
		}

    #endregion

    public override bool Equals(object obj) {
			Brush b = obj as Brush;
			if (b != null)
				return b.Color.Equals(Color);
			else
				return false;
		}

		public override int GetHashCode() {
			return base.GetHashCode ();
		}
    }
#endregion 





COLOR CLASS
// ===========================================================================
//	2013 WebSupergoo. All rights reserved.
// ===========================================================================

using System;

namespace WebSupergoo.ABCpdf10.Drawing {
	#region Color
	/// <summary>
	/// A color in RGB, CMYK or Grayscale.
	/// </summary>
	public class Color {
		#region Declare variables
		internal double a = 1;
		internal double r = 0;
		internal double g = 0;
		internal double b = 0;
		internal double c = 0;
		internal double m = 0;
		internal double y = 0;
		internal double k = 0;
		internal double gray = 0;
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the alpha component.
		/// </summary>
		public double A {
			get { return a; }
			set { a = value; }
		} 
		
		/// <summary>
		/// Gets or sets the red component.
		/// </summary>
		public double R {
			get { return r; }
			set { r = value; }
		} 

		/// <summary>
		/// Gets or sets the green component.
		/// </summary>
		public double G {
			get { return g; }
			set { g = value; }
		} 

		/// <summary>
		/// Gets or sets the blue component.
		/// </summary>
		public double B {
			get { return b; }
			set { b = value; }
		} 

		/// <summary>
		/// Gets or sets the cyan component.
		/// </summary>
		public double C {
			get { return c; }
			set { c = value; }
		} 

		/// <summary>
		/// Gets or sets the magenta component.
		/// </summary>
		public double M {
			get { return m; }
			set { m = value; }
		} 

		/// <summary>
		/// Gets or sets the yellow component.
		/// </summary>
		public double Y {
			get { return y; }
			set { y = value; }
		} 

		/// <summary>
		/// Gets or sets the black component.
		/// </summary>
		public double K {
			get { return k; }
			set { k = value; }
		} 

		/// <summary>
		/// Gets or sets the gray level.
		/// </summary>
		public double GrayScale {
			get { return gray; }
			set { gray = value; }
		} 
		#endregion

		public override bool Equals(object obj) {
			Color c = obj as Color;
			if (c != null)
				return (A == c.A) && (R == c.R) && (G == c.G) && (B == c.B)/>/>;
			else
				return false;
		}

		public override int GetHashCode() {
			return base.GetHashCode ();
		}

		#region Static methods
		/// <summary>
		/// Creates a Color from the specified 8-bit color values 
		/// (red, green, and blue). The alpha value is implicitly 255 (fully opaque). 
		/// </summary>
		/// <param name="red">The red component value. Valid values are 0 through 255.</param>
		/// <param name="green">The green component value. Valid values are 0 through 255.</param>
		/// <param name="blue">The blue component value. Valid values are 0 through 255.</param>
		/// <returns>The Color that this method creates.</returns>
		public static Color FromArgb(int red, int green, int blue) {
			return FromArgb(255, red, green, blue);
		}



        /// <summary>
        /// Creates a Color from a 32-bit ARGB value.
        /// </summary>
        /// <param name="argb">A value specifying the 32-bit ARGB value.</param>
        /// <returns>The Color that this method creates.</returns>
        public static Color FromArgb(int argb) {
			System.Drawing.Color clr = System.Drawing.Color.FromArgb(argb);
			return FromArgb(clr.A, clr.R, clr.G, clr.B)/>/>;
		}

      

        /// <summary>
        /// Creates a Color from the specified pre-defined color.
        /// </summary>
        /// <param name="color">An element of the System.Drawing.KnownColor enumeration.</param>
        /// <returns>The Color that this method creates.</returns>
        public static Color FromKnownColor(System.Drawing.KnownColor color) {
			System.Drawing.Color sysColor = System.Drawing.Color.FromKnownColor(color);
			return FromArgb(sysColor.A, sysColor.R, sysColor.G, sysColor.B)/>/>;
		}

		/// <summary>
		/// Creates a Color from the specified System.Drawing.Color structure, 
		/// but with the new specified alpha value. 
		/// </summary>
		/// <param name="alpha">The alpha value for the new System.Drawing.Color structure. Valid values are 0 through 255.</param>
		/// <param name="baseColor">The System.Drawing.Color structure from which to create the new System.Drawing.Color structure.</param>
		/// <returns>The Color that this method creates.</returns>
		public static Color FromArgb(int alpha, System.Drawing.Color baseColor) {
			return FromArgb(alpha, baseColor.R, baseColor.G, baseColor.B)/>/>;
		}
		
		/// <summary>
		/// Creates a Color from the specified 8-bit RGB color values 
		/// (alpha, red, green, and blue). 
		/// </summary>
		/// <param name="alpha">The alpha component value. Valid values are 0 through 255.</param>
		/// <param name="red">The red component value. Valid values are 0 through 255.</param>
		/// <param name="green">The green component value. Valid values are 0 through 255.</param>
		/// <param name="blue">The blue component value. Valid values are 0 through 255.</param>
		/// <returns>The Color that this method creates.</returns>
		public static Color FromArgb(int alpha, int red, int green, int blue) {
			Color clr = new Color();
			clr.a = alpha / 255F;
			clr.r = red / 255F;
			clr.g = green / 255F;
			clr.b = blue / 255F;
			return clr;
		}

		/// <summary>
		/// Creates a Color from the specified ARGB color values 
		/// (alpha, red, green, and blue). 
		/// </summary>
		/// <param name="cyan">The alpha component. Valid values are 0 through 1.</param>
		/// <param name="magenta">The red component. Valid values are 0 through 1.</param>
		/// <param name="yellow">The green component. Valid values are 0 through 1.</param>
		/// <param name="black">The blue component. Valid values are 0 through 1.</param>
		/// <returns>The Color that this method creates.</returns>
		public static Color FromArgb(double alpha, double red, double green, double blue) {
			Color clr = new Color();
			clr.a = alpha;
			clr.r = red;
			clr.g = green;
			clr.b = blue;
			return clr;
		}

		/// <summary>
		/// Creates a Color from the specified CMYK color values 
		/// (cyan, magenta, yellow, and black). 
		/// </summary>
		/// <param name="cyan">The cyan component. Valid values are 0 through 1.</param>
		/// <param name="magenta">The magenta component. Valid values are 0 through 1.</param>
		/// <param name="yellow">The yellow component. Valid values are 0 through 1.</param>
		/// <param name="black">The black component. Valid values are 0 through 1.</param>
		/// <returns>The Color that this method creates.</returns>
		public static Color FromCmyk(double cyan, double magenta, double yellow, double black) {
			Color clr = new Color();
			clr.c = cyan;
			clr.m = magenta;
			clr.y = yellow;
			clr.k = black;
			return clr;
		}

		/// <summary>
		/// Creates a Color from the specified gray level.
		/// </summary>
		/// <param name="gray">The gray component. Valid values are 0 through 1.</param>
		/// <returns>The Color that this method creates.</returns>
		public static Color FromCmyk(double gray) {
			Color clr = new Color();
			clr.gray = gray;
			return clr;
		}

		/// <summary>
		/// Gets a system defined color
		/// </summary>
		public static Color AliceBlue { get { return FromKnownColor(System.Drawing.KnownColor.AliceBlue); } }
public static Color Yellow { get { return FromKnownColor(System.Drawing.KnownColor.Yellow); } }

LIST of colors goes on..





Is This A Good Question/Topic? 0
  • +

Replies To: Getting a Color Value from a ComboBox

#2 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7462
  • View blog
  • Posts: 25,113
  • Joined: 05-May 12

Re: Getting a Color Value from a ComboBox

Posted 21 June 2016 - 08:53 PM

How are you populating the combobox? Is this a WebForms, WinForms, or WPF combobox?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1