Change string to color in VB.NET

Hi,

I am writing a VB.NET app that displays a colordialog and then captures the name of a color and saves it in an XML file.  The code if use is something like this:

dim fColor as String=colorDialog1.Color.Name

This works fine.  However, how do I convert the string value back into a color?  I have tried:

lblSample.BackColor = Color.FromKnownColor(fColor) but this only works for colors where the name property returns "Red", "Blue", "Green", etc.  It does not seem to work for colors where the name property returns strings like ff804040 or ffff8000.

Any help will be greatly appreciated!!!

Many thanks
Vyyk
Vyyk_DragoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wim_BlCommented:
Hi,

I think the value that is returned is the RGB representation of the color (Red Green Blue), so if you split this into the three different parts and then use the RGB(red value, green value, blue value) function, you might be able to accomplish your goal.
Not sure if this work and can't test it now, but maybe give it a shot!

greetings,
Wim
0
AgentSmith007Commented:
What if you store the Argb value to the xml file? You can use color.toArgb to get the integer value of the color & then return the color by using dim MyColor as color = color.FromArgb(integer)
0
RobertRFreemanCommented:
You should use color.fromname(fColor)
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Vyyk_DragoAuthor Commented:
Basically I want to use the colors stored in the xml file to be used to manipulate colors in an html file and it seems that using the ARGB values do not translate properly if they are used as color values in html.  For instance, if I choose orange from the color dialog and save the ARGB, it turns the html file generated off the ARGB value pale yellow.

I have also used

lblSample.BackColor = Color.FromName(fColor)

but that only works for colors where the Name property returns the color of the name, not if it returns a value like
ff804040 or ffff8000.
0
AgentSmith007Commented:
Look @ this.
        Dim MyColor As Color = Color.FromName("Red")
        Dim strColor As Color = MyColor.FromArgb(MyColor.ToArgb)
0
AgentSmith007Commented:
sry:

        Dim MyColor As Color = Color.FromName("Red")
        MyColor = MyColor.FromArgb(MyColor.ToArgb)
      messagebox.show(MyColor.Name)
0
RobertRFreemanCommented:
Use ColorTranslator.ToHTML and ColorTranslator.FromHTML
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vyyk_DragoAuthor Commented:
Thanks Robert - that is perfect!  A lot easier than I thought it would be.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.