Solved

Color.Name return the name not fffetc.

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DataGridView Events ? 3 45
Allow user to hide and show datagridview columns 4 25
VB.Net - TypeInitializer Error 25 26
vb.net help 4 29
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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