Search EggHeadCafe's Job Board
EggHeadCafe Silverlight WPF ASP.NET VB.NET C# Excel SQL Server SharePoint
search
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

WebArticlesForumsFAQs
JavaScript
ASP
ASP.NET
WCF

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

Operating SysArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Lounge
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

ASP.NET Color Tool Derived from Reflection


By beto74 dixon
Printer Friendly Version
View My Articles
35 Views
    

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
        
    protected void Page_Load(object sender, EventArgs e)
    {

        Type t = typeof(System.Drawing.Color);

        foreach (PropertyInfo fi in t.GetProperties())
        {
            if (fi.PropertyType.ToString() == "System.Drawing.Color")
            {
                string colorName = fi.Name;
                
                Label lbl = new Label();
                LiteralControl lit = new LiteralControl();
                Color c = 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(lbl);
                phl.Controls.Add(new LiteralControl("&nbsp;"));
                phl.Controls.Add(lit);
                phl.Controls.Add(new LiteralControl("<br />")); 
            }
        }
       
    }

 

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>System.Drawing.Color</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:PlaceHolder ID="phl" runat="server"></asp:PlaceHolder>
    </form>
</body>
</html>



button
Article Discussion: Web based colour tool
beto74 dixon posted at Tuesday, October 02, 2007 5:19 AM
Original Article