Reader Level:
Visual Basic .NET

Web based colour tool in VB .NET

By Rob on Nov 10 2012
This article gives you information about the System.Drawing namespace, which is very useful while working with colours in your .net projects
    • Like
    • Love It
    • Awesome
    • Interesting
    • It's Okay
    • Thumbs Down
  • 3.8k
  • 0


The .NET Framework provides us with over 100 colours to use within the System.Drawing namespace. In order that we know exactly what all these colours look like here is a simple web based tool that uses Reflection to loop through all the colours with the System.Drawing.Color struct and print them to the page.


<%@ Page Language="C#" %>

<%@ Import Namespace="System.Reflection" %>

<%@ Import Namespace="System.Drawing" %>

<%@ Import Namespace="System.Drawing.Imaging" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""">


<script runat="server">


Protected Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs) 

    Dim t As Type = GetType(System.Drawing.Color) 

    For Each fi As PropertyInfo In t.GetProperties()

        If fi.PropertyType.ToString() = "System.Drawing.Color" Then

            Dim colorName As String = fi.Name 

            Dim lbl As New Label()

            Dim lit As New LiteralControl()

            Dim c As Color = System.Drawing.Color.FromName(colorName) 

            lit.Text = "System.Drawing.Color." + colorName 

            lbl.BackColor = c

            lbl.Width = Unit.Pixel(300)

            lbl.Height = Unit.Pixel(20)

            lbl.BorderWidth = Unit.Pixel(1) 


            phl.Controls.Add(New LiteralControl("&nbsp;"))


            phl.Controls.Add(New LiteralControl("<br />"))

        End If


End Sub 


<html xmlns="" >

<head id="Head1" runat="server">




    <form id="form1" runat="server">

    <asp:PlaceHolder ID="phl" runat="server"></asp:PlaceHolder>