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 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.