Listbox and colors

UCM

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

so far, no luck -_-

any ideas?
Visual Basic:
    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
 
I haven't tested this yet, but you might be able to get all the fields
in the KnownColor type to get them.
Visual Basic:
Dim col As Reflection.FieldInfo

For Each col In GetType(KnownColor).GetFields
    ListBox1.Items.Add(col.Name)
Next
 
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 I've come:
Visual Basic:
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
 
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:
Visual Basic:
If col.FieldType Is GetType(Drawing.KnownColor) Then
 
Here's another, possibly better way:
Visual Basic:
Dim cols() As String

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

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


thanx again, VolteFace
 
Back
Top