473,320 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Brush By Name

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.

Nov 15 '05 #1
1 4822
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

"Rene" <no****@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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.

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Serdar YILMAZ | last post by:
2
by: boxim | last post by:
having a moment, cant you just Brush br = new Brush(Color.Black);??? saying you cant cos it's an abstract class need to get to a brush from a color tia sam martin
3
by: jcrouse | last post by:
I have the following string: e.Graphics.DrawString(Label5.Text, lblP1B1.Font, Brushes.White, -y, 0) I want to use the property label.forecolor for my text color. How do I get whats in...
5
by: Dennis | last post by:
When I instantiate a Brush resource such as a solidbrush, do I need to dispose the resource when I'm finished or will it automatically be disposed when the function/sub it's used in ends? Thank...
2
by: JR | last post by:
Hi, I need a color to Brush convert function. something like this Function GetColorBrush(cColor as color) as brush dim sColor as string = cColor.name return brushes(sColor) End function ...
1
by: =?Utf-8?B?UEtsZW1t?= | last post by:
how to serialize a brush object with the XmlSerializer without knowing the brush type?
2
by: Johnny J. | last post by:
I've got an inherited control where I want the user to be able to specify a color property. Using that color, I'm drawing a line private m_UserDefinedColor as Color ..... Dim g as...
0
by: steve | last post by:
When drawing with a hatch brush with a statement such as myGraphics.FillPolygon(hatchBrush, polygon.vertices); the hatch brush is always oriented in the same direction. Is there a way of...
31
by: Tom P. | last post by:
I am doing quite a bit of custom painting and it means I have to create a lot of brushes (think one for every file system object in a directory) per paint. How expensive is this? Should I find a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.