Solved

Color.Name return the name not fffetc.

Posted on 2009-04-07
5
198 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

759 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

23 Experts available now in Live!

Get 1:1 Help Now