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.
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
using System;
using WebSupergoo.ABCpdf10.Drawing;
namespace WebSupergoo.ABCpdf10.Drawing
{
public interface Brush
{
Color Color { get; set; }
}
}
#region SolidBrush
public sealed class SolidBrush : Brush {
#region Declare variables
Color _color;
#endregion
#region Properties
public Color Color {
get { return _color; }
set { _color = value; }
}
#endregion
#region Constructors
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.
using System;
namespace WebSupergoo.ABCpdf10.Drawing {
#region Color
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
public double A {
get { return a; }
set { a = value; }
}
public double R {
get { return r; }
set { r = value; }
}
public double G {
get { return g; }
set { g = value; }
}
public double B {
get { return b; }
set { b = value; }
}
public double C {
get { return c; }
set { c = value; }
}
public double M {
get { return m; }
set { m = value; }
}
public double Y {
get { return y; }
set { y = value; }
}
public double K {
get { return k; }
set { k = value; }
}
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
public static Color FromArgb(int red, int green, int blue) {
return FromArgb(255, red, green, blue);
}
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);
}
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);
}
public static Color FromArgb(int alpha, System.Drawing.Color baseColor) {
return FromArgb(alpha, baseColor.R, baseColor.G, baseColor.B);
}
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;
}
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;
}
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;
}
public static Color FromCmyk(double gray) {
Color clr = new Color();
clr.gray = gray;
return clr;
}
public static Color AliceBlue { get { return FromKnownColor(System.Drawing.KnownColor.AliceBlue); } }
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
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.
new SolidBrush(combobox1.selecteditem)