Solved

Color.Name return the name not fffetc.

Posted on 2009-04-07
5
199 Views
Last Modified: 2012-05-06
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
Comment
Question by:Sheritlw
  • 3
  • 2
5 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 24091392
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
 

Author Comment

by:Sheritlw
ID: 24091555
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
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 24091849
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
 

Author Comment

by:Sheritlw
ID: 24092680
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
 
LVL 48

Expert Comment

by:jpaulino
ID: 24094547
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check if number is currency 15 31
Create a form which is copy of a form in vb.net 2 34
Passing a form as a parameter to an external class 1 27
Variable Event ? 3 20
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

919 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now