Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set color from text value 1

Status
Not open for further replies.

krisbrixon

Programmer
May 10, 2002
371
US
Right now I have the following code to set the alternate color for listview's

Public Shared gBackGoundColor As System.Drawing.Color = System.Drawing.Color.LightBlue

Now, I want to have a combobox with a listing of colors that the user can select and set the gBackGroundColor to the value of the combobox. (I do not want to use colorpicker)

i.e. Let's say they pick "Green". So, how do I change the String value of Green to the System.Drawing.Color of Green?

---

(In reality this is an example of a larger question. Is it possible to have a string variable(s1) hold the name of another object(s2) and get the program to use the value that is represented in S1?)
For example:
In Clipper you could have:
sVar2 := "Test001"
sVar1 := "sVar2"
---
? sVar1 'Would Print = sVar2
? (sVar1) 'Would Print = "Test001"
? sVar2 'Would Print = "Test001"


Thanks

Kris
 
Ya make a class that has two string objects in it. Set the toString method of the class to return the string you want.

Something simple liek that should work. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
I have a string I need to change that to a system.drawing.color

Kris
 
And I was saying store the string and system.drawing.color side by side in a class designed specifically for that.

Or you could do a Case statement.
Select string
Case "Green
gBackGoundColor = system.drawing.color.green
...
....
.....

I like the class idea better though. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
does a standard desktop dropdown list not have a value attribute and a text attribute?

i.e. store "green" in the text, and the constant equivalent in the value (1,3,4, etc...)

penny1.gif
penny1.gif
 
It unfortunately does not Paul. Only us lucky web programmers get that special treatment. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Then, yes, a custom class is in order that will index those values and return what you need.

peeew
penny1.gif
penny1.gif
 
Thanks for your help, it was not what I really wished for, but it is a good idea.

Kris
- If it ain't broke, fix it till it is.
 
Thnx for the star and your welcome. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top