?
Solved

Change string to color in VB.NET

Posted on 2005-02-24
8
Medium Priority
?
6,140 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:Vyyk_Drago
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 9

Expert Comment

by:Wim_Bl
ID: 13395477
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
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 13395519
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
 
LVL 16

Expert Comment

by:RobertRFreeman
ID: 13395575
You should use color.fromname(fColor)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Vyyk_Drago
ID: 13395639
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
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 13395718
Look @ this.
        Dim MyColor As Color = Color.FromName("Red")
        Dim strColor As Color = MyColor.FromArgb(MyColor.ToArgb)
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 13395733
sry:

        Dim MyColor As Color = Color.FromName("Red")
        MyColor = MyColor.FromArgb(MyColor.ToArgb)
      messagebox.show(MyColor.Name)
0
 
LVL 16

Accepted Solution

by:
RobertRFreeman earned 2000 total points
ID: 13395743
Use ColorTranslator.ToHTML and ColorTranslator.FromHTML
0
 

Author Comment

by:Vyyk_Drago
ID: 13395796
Thanks Robert - that is perfect!  A lot easier than I thought it would be.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month13 days, 5 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question