Brush By Name

  • Thread starter Thread starter Rene
  • Start date Start date
R

Rene

I would like to get a reference to a Brush using the color name of the
brush. For example, right now if I want a brush with a certain color, I
would hard code something like Brushes.PeachPuff, this will get me a
PeachPuff brush, but what if my brush depended on a string passed by the
user? If all I had was a string with the name "PeachPuff" how can I create
Brushes.PeachPuff using the string value?

Thank you.
 
Look at Reflection and Type.InvokeMember:

more specifically, I think this will do it for you (although I haven't
tested it very thoroughly):
Type brushType = typeof(Brushes);

Brush myBrush = (Brush) brushType.InvokeMember("PeachPuff",
BindingFlags.Public | BindingFlags.Static| BindingFlags.GetProperty ,
null, null, new object [] {});

-mike
 
Back
Top