Listbox and colors

UCM

Centurion
Joined
Jan 1, 2003
Location
Colorado, usa
Ive been trying to modify that code to allow me to get the names of all the known colors...

so far, no luck -_-

any ideas?
Code:
    Dim ff2 As String
    Dim ifc1 As System.Drawing.KnownColor

    For Each ff2 In ifc1
      Dim zz = ComboBox3.Items.Add(ff2)
      If ff.Name = "Black" Then ComboBox3.SelectedIndex = zz
    Next
 

Volte

Neutiquam Erro
Joined
Nov 17, 2002
User Rank
*Expert*
I havent tested this yet, but you might be able to get all the fields
in the KnownColor type to get them.
Code:
Dim col As Reflection.FieldInfo

For Each col In GetType(KnownColor).GetFields
    ListBox1.Items.Add(col.Name)
Next
 

UCM

Centurion
Joined
Jan 1, 2003
Location
Colorado, usa
niiice, VolteFace...

it got the name of every property including the color names :)

hmmm... how do we get it to refrain from pulling in the non-color properties...

So far this is the closest Ive come:
Code:
Dim col As Reflection.FieldInfo

For Each col In GetType(KnownColor).GetFields
    If col.MemberType.GetTypeCode = TypeCode.Int32 Then
      ComboBox3.Items.Add(col.Name)
    End If
Next
 

Volte

Neutiquam Erro
Joined
Nov 17, 2002
User Rank
*Expert*
What non-color fields do you mean? The only non-color field I can see
is value__ and that is easily removed.

However, I believe the correct way to filter them would be this:
Code:
If col.FieldType Is GetType(Drawing.KnownColor) Then
 

Volte

Neutiquam Erro
Joined
Nov 17, 2002
User Rank
*Expert*
Heres another, possibly better way:
Code:
Dim cols() As String

cols = [Enum].GetNames(GetType(KnownColor))
ListBox1.Items.AddRange(cols)
 

UCM

Centurion
Joined
Jan 1, 2003
Location
Colorado, usa
Sweet!!

yup, your better way does work best... GetType... Think Ill do some additional research on that ;)


thanx again, VolteFace
 
Top