I have already shown how to use .NET reflection to get the information about all the colors in .NET. Let's say you want to check out how a specific colored font would appear on any background, you may like to check this sample.
Use the code which follows to get an output like the one below.
There are various ways to get this output, but I guess this code is pretty small and will show you some of the things that you could do with System.Reflection in .NET.
Here is the code...
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Reflection" %>
<%@ Import Namespace="System.Drawing" %>
<!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)
{
string strColor = string.Empty;
if (Request.QueryString.Get("color") != null)
strColor = Request.QueryString.Get("color");
else
strColor = "White";
Response.Write("<BR><BR><BR><BR>");
Response.Write("<Table width='100%' border=1 cellspacing=1 cellpadding=5>");
Response.Write("<TR bgcolor='LightCyan'><TD width='15%'><B>Color Name</B></TD><TD width='30%'>" +
"<B>Color</B></TD><TD width='15%'>Color Code</TD>");
//Get the assembly's information
Color x = new Color();
Color ColorInformation;
Type strType = x.GetType();
string strColorHexCode = string.Empty;
string strColorName = string.Empty;
string strPath = Request.ApplicationPath + "/samples/color/color2.aspx?color=";
MemberInfo[] arrMemberInfo = strType.GetProperties();
//Lets Enumerate the colors now
foreach (MemberInfo myMemberInfo in arrMemberInfo)
{
//Get the RGB components from the color and convert them to Hex with 2 places.
ColorInformation = Color.FromName(myMemberInfo.Name);
strColorName = myMemberInfo.Name;
strColorHexCode = "#" + ColorInformation.R.ToString("X2") +
ColorInformation.G.ToString("X2") +
ColorInformation.B.ToString("X2");
Response.Write("<TR>");
Response.Write("<TD><a href='" + strPath + strColorName + "'>");
Response.Write(strColorName + "</a>");
Response.Write("<TD align='center' bgcolor='" + strColorName);
Response.Write("'><font color='" + strColor + "'>---------- ");
Response.Write(strColor + " on " + strColorName + " BackGround ----------</font></TD>");
Response.Write("<TD><a href='" + strPath + strColorName + "'>");
Response.Write(strColorHexCode + "</a></TD></TR>");
if (myMemberInfo.Name == "YellowGreen")
break;
}
Response.Write("</Table>");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Color Sample 2</title>
</head>
<body style ="font-family:verdana">
<div style="position:absolute; top:10">
<form id="form1" runat="server">
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="http://www.dotnetscraps.com/pics/dotnetscraps-logo.gif"
PostBackUrl="http://www.dotnetscraps.com" />
</form>
</div>
</body>
</html>
Check this sample live.
Hope this helps
Rahul