[Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Color.Name return the name not fffetc.

I am using the color dialog to assign a color and the color name to a text box.
Unfortunetly the Color.Name will sometimes bring back the alpha/numeric version instead of the actual name, like the constants.
Users will not want to see the color symbols, only the color name, like light yellow, etc.
How do I get the actual name of the color?
Please provide an example.  I can't click on links without my IE crashing.
Thanks
0
Sheritlw
Asked:
Sheritlw
  • 3
  • 2
1 Solution
 
jpaulinoCommented:
Hi Sheritlw,

You can show this way
        Dim c As New ColorDialog
        c.ShowDialog()
        Debug.WriteLine(c.Color.Name.ToString)

Open in new window

0
 
SheritlwAuthor Commented:
Hi jpaulino,

Unfortunetly that doesn't work.   I tried that and on a few colors it will return the name, but on the majority it doesn't.
This is the code I use
 Dim c As New ColorDialog
        c.AllowFullOpen = True
        c.AnyColor = True
        c.SolidColorOnly = True

        c.ShowHelp = True
        If c.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.txtCarColor.BackColor = c.Color
            Me.txtCarColor.Text = c.Color.Name.ToString
        End If
0
 
jpaulinoCommented:
Not all colors have names :)
You can check if the name IsNamedColor before show that information

 Dim c As New ColorDialog
        c.AllowFullOpen = True
        c.AnyColor = True
        c.SolidColorOnly = True
 
        c.ShowHelp = True
        If c.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.txtCarColor.BackColor = c.Color
            If c.Color.IsNamedColor Then
                 Me.txtCarColor.Text = c.Color.Name.ToString
            End IF
        End If

Open in new window

0
 
SheritlwAuthor Commented:
I really need to have a name in the text box.  Is there anyway to retrieve the constant name, or maybe just show colors that have a constant assigned?
0
 
jpaulinoCommented:
With that picker I don't think you can, but maybe you can create or use a picker that only use namedcolors like this one: http://www.codeproject.com/KB/combobox/ColorComboBox.aspx
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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