Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i am having a hard time assigning a color value to a drawing. What i am trying to do is pick from a comboBox value which has a color values.

C#
foreach (System.Reflection.PropertyInfo prop in typeof(WebSupergoo.ABCpdf10.Drawing.Color).GetProperties())
{
                if (prop.PropertyType.FullName == "WebSupergoo.ABCpdf10.Drawing.Color")
                    colorComboBox.Items.Add(prop.Name);
            }






Since this is a third party control, i will try to paste the other classes since the color class doesn't directly derived from system.drawing.color.

Here's the solidbrush class
C#
// ===========================================================================
//	©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 



and here is the color class itself as well.

C#
// ===========================================================================
//	©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); } }

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

	
}


Thank you codeproject..

What I have tried:

Here's is the code of assigning a color at design time which work, no problem
C#
new SolidBrush(Color.Aqua)


So it get's a little cleaner now what i am trying to accomplish..

So the code I'm trying to achieve is like this.

C#
new SolidBrush(combobox1.selecteditem)
Posted
Comments
Sergey Alexandrovich Kryukov 21-Jun-16 20:43pm    
As I can see, this is a proprietary commercial product. Why asking such questions here? It's not very likely that you get help. Rather, you can demand some help via their customer support.
—SA
derstine 21-Jun-16 20:46pm    
Im sorry
Sergey Alexandrovich Kryukov 21-Jun-16 23:53pm    
No, I'm sorry. :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900