Getting Named Color Names and values????

  • Thread starter Thread starter SStory
  • Start date Start date
S

SStory

How can I get value pairs of named colors and the color they represent?

I want to easily get these colornames and then their associated color values
into a file so I can add to the list and offer this list in an owner drawn
listbox for the user to choose colors.

thanks,

Shane
 
Nevermind, I found out how to get these.

Below is a sample for anyone else who reads this and might not know..

there may be a better way but this will get the info in a file for me and
that is all I care about... and there may be more than 165 known colors but
I don't think so.
Dim c As Color
For i As Byte = 0 To 165
c = Color.FromKnownColor(i)
Debug.WriteLine(String.Format("{0} : {1},{2},{3}",
c.ToKnownColor.ToString(), c.R, c.G, c.B))
Next
 
* "SStory said:
How can I get value pairs of named colors and the color they represent?

I want to easily get these colornames and then their associated color values
into a file so I can add to the list and offer this list in an owner drawn
listbox for the user to choose colors.

\\\
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ListBox1.DataSource = [Enum].GetNames(GetType(KnownColor))
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Me.ListBox1.BackColor = Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor), CStr(ListBox1.SelectedItem)), KnownColor))
End Sub
///
 
Wow that is an awesome solution. I will have to try it.
I choose to write all of those to an XML file so that the user can add
his/her own colors to the list.

Shane

Herfried K. Wagner said:
\\\
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.ListBox1.DataSource = [Enum].GetNames(GetType(KnownColor))
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Me.ListBox1.BackColor =
Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor),
CStr(ListBox1.SelectedItem)), KnownColor))
 
Could you tell me what this [Enum] is exactly?
What object does it belong to? Object?

I assume it is hidden?

Thanks,

Shane


Herfried K. Wagner said:
\\\
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.ListBox1.DataSource = [Enum].GetNames(GetType(KnownColor))
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Me.ListBox1.BackColor =
Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor),
CStr(ListBox1.SelectedItem)), KnownColor))
 
* "SStory said:
Could you tell me what this [Enum] is exactly?
What object does it belong to? Object?

It's the 'Enum' class. 'Enum' is a keyword in VB.NET, so we have to
"escape" it with the square brackets.
I assume it is hidden?

No, it isn't ;-).
 
Cool! This is one of the greatest things I've learned lately. Will be
helpful in many ways.

Danke sehr gut,

Herfried

Herfried K. Wagner said:
* "SStory said:
Could you tell me what this [Enum] is exactly?
What object does it belong to? Object?

It's the 'Enum' class. 'Enum' is a keyword in VB.NET, so we have to
"escape" it with the square brackets.
I assume it is hidden?

No, it isn't ;-).
 
Back
Top