473,322 Members | 1,718 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,322 software developers and data experts.

How to get the Color value from SystemColors

I am being passed a string, such as ControlText. From this string, I
must figure its color value and set that value to a control.

All these values are stored in the System.Drawing.SystemColors.* enums.
I've tried to pry it open with Enum.Parse, but no dice, it keeps giving
me exceptions of all kinds.

Has anyone else figured out how to get the value of the Enum from a
string form?

Thanks.
Nov 16 '05 #1
4 3858
Frank Rizzo wrote:
I am being passed a string, such as ControlText. From this string, I
must figure its color value and set that value to a control.

All these values are stored in the System.Drawing.SystemColors.* enums.
I've tried to pry it open with Enum.Parse, but no dice, it keeps giving
me exceptions of all kinds.

Has anyone else figured out how to get the value of the Enum from a
string form?

Thanks.


I just looked at it again and all the Colors in both SystemColors and
Color classes are actually properties. So, the question is how to get a
property based on the name of the property.
Nov 16 '05 #2
SomeControl.BackColor = Color.FromName("Info")

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Frank Rizzo" <no**@none.com> wrote in message
news:OI*************@TK2MSFTNGP15.phx.gbl...
I am being passed a string, such as ControlText. From this string, I must
figure its color value and set that value to a control.

All these values are stored in the System.Drawing.SystemColors.* enums.
I've tried to pry it open with Enum.Parse, but no dice, it keeps giving me
exceptions of all kinds.

Has anyone else figured out how to get the value of the Enum from a string
form?

Thanks.

Nov 16 '05 #3
You can use Color.FromName("ControlText") to get the Color object associated
with that system color. In my pc, for instance, that returns a Color object
with R=0, G=0, B=0.

Here's an interesting article about a security flaw related to using
Color.FromName, though. This article rightly suggests using a TypeConverter
to extract a Color from a string.

http://www.nikhilk.net/CrossSiteScri...ithColors.aspx

If that doesn't help, and you still want to get the value of a property
based on a string name of the property, use the
System.Reflection.PropertyInfo class. Here's an example from a recent
project of mine that may help you get started. It is from a control used in
an asp.net page. It looks for a property named CurrentServer of type
RequestedServer in the page that contains the control that this code is
from.

Type pageType = (Page.GetType());

PropertyInfo myPropertyInfo = pageType.GetProperty("CurrentServer");

if (myPropertyInfo != null)

{

requestedServer = (RequestedServer)myPropertyInfo.GetValue(Page,null );

}
Good luck,

DalePres
MCAD, MCSE, MCDBA
"Frank Rizzo" <no**@none.com> wrote in message
news:u8**************@TK2MSFTNGP14.phx.gbl...
Frank Rizzo wrote:
I am being passed a string, such as ControlText. From this string, I
must figure its color value and set that value to a control.

All these values are stored in the System.Drawing.SystemColors.* enums.
I've tried to pry it open with Enum.Parse, but no dice, it keeps giving
me exceptions of all kinds.

Has anyone else figured out how to get the value of the Enum from a
string form?

Thanks.


I just looked at it again and all the Colors in both SystemColors and
Color classes are actually properties. So, the question is how to get a
property based on the name of the property.

Nov 16 '05 #4


form2 frm2 = new form2()

form1.Hide()
frm2.show()
"Frank Rizzo" <no**@none.com> wrote in message
news:OI*************@TK2MSFTNGP15.phx.gbl...
I am being passed a string, such as ControlText. From this string, I must
figure its color value and set that value to a control.

All these values are stored in the System.Drawing.SystemColors.* enums.
I've tried to pry it open with Enum.Parse, but no dice, it keeps giving me
exceptions of all kinds.

Has anyone else figured out how to get the value of the Enum from a string
form?

Thanks.

Nov 16 '05 #5

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

Similar topics

0
by: Jake | last post by:
What is the System.Drawing.Color equivalent of System.Drawing.SystemColors.Control for default XP form background color? (It's the light tan). If there is no equivalent, how could I read a color...
5
by: Guy | last post by:
Guys Hope someone can help me! I'm having real problems getting properties I type against a control I have written at design time I have written a control by inheriting from the Button control....
3
by: AussieRules | last post by:
Hi, In XP you can set color schemes (olive green, silver, default blue). I have some controls(panels) on my form, and I would like to set the color as per the color of the scheme. Can this...
36
by: AussieRules | last post by:
Hi, I want to use the user color scheme to set the color of my forms. I now I have to use the. System.Drawing.SystemColors, but which color is the color of a form background as used in other...
7
by: beetdocta | last post by:
hello i was wondering is it possible in visual basic .net to change the color of certain words or phrases without changing the color of all the text in the lable or without having to create a new...
1
by: MuZZy | last post by:
Hi, I'm trying to find a way to find out a form menu height/color as i think it changes depending on various Windows settings. I need to create a form of height/color of form menu so that i can...
1
by: Kevin L | last post by:
Can anyone tell me the RGB values for the "Control" System Color? Thanks
6
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I want to specify a custom color for disabled text that is used by a class that inherits from ToolStripProfessionalRenderer. The code would look something like this: Public Class MyRenderer...
1
by: thomasc | last post by:
Hello, This is about VB.NET2003. I'm trying to obtain the RGB value of a Windows system color and use it as the background color of my Microsoft Word file. But I have not been able to find...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: 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.