Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6186
  • Last Modified:

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
0
Vyyk_Drago
Asked:
Vyyk_Drago
  • 3
  • 2
  • 2
  • +1
1 Solution
 
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
Industry Leaders: 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!

 
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
 
Vyyk_DragoAuthor Commented:
Thanks Robert - that is perfect!  A lot easier than I thought it would be.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now