I have a property that lets me pass a string name of a known color to my control. The property accepts only known color names, such as "Red" or "Blue."
private KnownColor _UseColor = KnownColor.Red;
public string ColorName
{
get
{
return this._UseColor.ToString();
}
set
{
if (Enum.IsDefined(typeof(KnownColor), value))
this._UseColour = (KnownColor)Enum.Parse(typeof(KnownColor), value);
}
}
And I want to use this enumeration _UseColourto select an existing brush from the static Brushes class in .NET. like this
Brush sysBrush = Brushes.FromKnownColor(this._UseColor);
e.Graphics.FillRectangle(sysBrush, 0, 0, 10, 10);
Instead of creating a new brush whenever the control is painted as
using (SolidBrush brsh = new SolidBrush(Color.FromKnownColor(this._UseColor)))
e.Graphics.FillRectangle(brsh, 0, 0, 10, 10);
Does anyone know if this is possible, or do I need to create a new brush every time?
Brushes.FromKnownColor not a class method Brushes
source
share