Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

   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

UCM

>-)

  • *Experts*
Posted

I haven't tested this yet, but you might be able to get all the fields

in the KnownColor type to get them.

Dim col As Reflection.FieldInfo

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

Posted

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:

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

UCM

>-)

  • *Experts*
Posted

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:

If col.FieldType Is GetType(Drawing.KnownColor) Then

  • *Experts*
Posted
Here's another, possibly better way:
Dim cols() As String

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

Posted

Sweet!!

 

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

 

 

thanx again, VolteFace

UCM

>-)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...