Click here to Skip to main content
11,720,545 members (79,148 online)
Click here to Skip to main content

Tagged as

Show your System.Drawing.Color Palette

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

Introduction

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:

DataGridView1.Rows.Add()

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_
            	(DataGridViewElementStates.Displayed)
            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
                DataGridView1.Rows.Add()
                rowcount = rowcount + 1
            End If
            
            cellcount += 1
        End If
    End If
Next 

Please provide feedback about my code.

License

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

Share

About the Author

anssary2010
Egypt Egypt
No Biography provided

You may also be interested in...

Comments and Discussions

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