I have a property that allows the string name of a known colour to be sent to my control. The property only accepts proper known colour names, like "Red" or "Blue"
private KnownColor _UseColor = KnownColor.Red;
/// <summary>
/// Gets or sets the name of the colour
/// </summary>
public string ColorName
{
get
{
return this._UseColor.ToString();
}
set
{
if (Enum.IsDefined(typeof(KnownColor), value))
this._UseColour = (KnownColor)Enum.Parse(typeof(KnownColor), value);
}
}
And what I want to do is use this _UseColour
enumeration to 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 like this
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 will I have to create a new brush every time?
Brushes.FromKnownColor
isn't a method in the Brushes
class