Click here to Skip to main content
12,747,162 members (27,423 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 24 Nov 2012

Show your System.Drawing.Color Palette

, 24 Nov 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
How to show your System.Drawing.Color palette


If you try to write a program and then you want to add code to highlight text by color, you will go and use System.Drawing.Color. But I will ask you a question. Do you know all colors in this class to set an appropriate color. This program will help you to create a palette that contains all colors in this class with its name so it will be useful to have an appropriate color and take its name.

Using the Code

This code loops through all properties of color class by using Reflection and then trying to get its name and value and putting it in grid cell:


Dim cellcount As Int16 = 1
Dim rowcount As Int16 = 0
Dim COLORs As System.Drawing.Color

For Each p As System.Reflection.PropertyInfo In COLORs.GetType().GetProperties()
    Dim modval As Int16
    If p.CanRead Then
        ' Dim OBJ As System.Drawing.Color
        Dim objType As Type = COLORs.GetType()
        Dim pInfo As System.Reflection.PropertyInfo = objType.GetProperty(p.Name)
        Dim PropValue As Object = pInfo.GetValue_
        (COLORs, Reflection.BindingFlags.GetProperty, Nothing, Nothing, Nothing)
        If TypeOf (PropValue) Is System.Drawing.Color Then
            modval = cellcount Mod 5
            If modval = 0 Then
                modval = 5
            End If
            Dim r As Int16 = DataGridView1.Rows.GetFirstRow_
            CallByName(DataGridView1.Item(modval - 1, rowcount).Style, _
            	"BackColor", CallType.Set, PropValue)
            CallByName(DataGridView1.Item(modval - 1, rowcount), _
            	"value", CallType.Set, p.Name)
            If modval = 5 Then
                rowcount = rowcount + 1
            End If
            cellcount += 1
        End If
    End If

Please provide feedback about my code.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Egypt Egypt
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170215.1 | Last Updated 24 Nov 2012
Article Copyright 2012 by anssary2010
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid