Hi,
Does anyone know how to iterate all the colors in vb.net??
the Color class has a lot of different colors and I want to put them all in a combo box.
Thanks,
Printable View
Hi,
Does anyone know how to iterate all the colors in vb.net??
the Color class has a lot of different colors and I want to put them all in a combo box.
Thanks,
Code:Imports System
Imports System.Reflection
Public Module ListColors
Public Sub Main(ByVal args() As String)
GetColors()
End Sub
Public Sub GetColors()
Dim asm As [Assembly] ' Assembly is reserved vb word so use the brackets to override
Dim myClasses() As Type
Dim myProperties() As PropertyInfo
Dim myTypeInfo As Type
Dim myPropertyInfo As PropertyInfo
' Lets load the System.Drawing dll
asm = [Assembly].LoadWithPartialName("System.Drawing")
If Not(asm Is Nothing) Then
' get an array of base classes
myClasses = asm.GetTypes()
End If
' Loop through each class
For Each myTypeInfo In myClasses
' if it is the color class
If myTypeInfo.ToString() = "System.Drawing.Color" Then
' get an array of all the properties
myProperties = myTypeInfo.GetProperties()
' loop the properties
For Each myPropertyInfo In myProperties
' if the property returns a Color object, then lets output it
' to the console as their are some non color properties we
' dont want to list
If myPropertyInfo.PropertyType.ToString() = "System.Drawing.Color" Then
Console.Writeline(myPropertyInfo.Name)
End If
Next myPropertyInfo
End If
Next myTypeInfo
End Sub
End Module