Results 1 to 2 of 2

Thread: Colors

  1. #1

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Colors

    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,
    Don't anthropomorphize computers -- they hate it

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width