<%-- <title>asp.net.ph Reference: Color Table</title> --%>
<%@ Import namespace="System.Drawing" %>
<script language="C#" runat="server">
Array colors;
void Page_Load ( object Source, EventArgs e ) {
if ( !IsPostBack )
colors = Enum.GetValues ( typeof ( KnownColor ) );
}
string hex ( Color c ) {
string r = c.R.ToString ( "x" );
r = r.Length < 2 ? r + r : r;
string g = c.G.ToString ( "x" );
g = g.Length < 2 ? g + g : g;
string b = c.B.ToString ( "x" );
b = b.Length < 2 ? b + b : b;
return ( r + g + b ).ToUpper ( );
}
</script>
<asp:content id="mainContent" contentplaceholderid="mainContent" runat="server">
<style type="text/css">
<!--
.colortable {border:thin outset; width:90%}
.colortable th {background:ghostwhite; padding:3; border:1px outset}
.colortable td {border:1px outset; padding:3}
-->
</style>
<div class="header"><h2>Color Table</h2></div>
<p class="small"><a href="../aspnetpagesyntax.aspx">ASP.NET Web Forms Syntax</a> <a href="../aspsyntaxforwebcontrols.aspx">Web Server Controls Syntax</a> <a href="../basewebcontrolproperties.aspx">Base WebControl Properties</a><hr size=1 width=92%>
<p>The following table shows each of the available colors and their equivalent values in the .NET Framework, as defined in the <b>System.Drawing.KnownColor</b> enumeration. Any element with a color property ( ForeColor, BackColor, etc. ) can take one of the following values.
<div class="header"><h3>Known Colors</h3></div>
<br>
<div align="center">
<table class="colortable">
<tr>
<th>Color</th>
<th>Name</th>
<th>Hex Value</th>
<th>Red Value</th>
<th>Green Value</th>
<th>Blue Value</th>
</tr>
<% foreach ( KnownColor k in colors ) {
Color c = Color.FromKnownColor ( k );
if ( !c.IsSystemColor ) {
string h = hex ( c ); %>
<tr>
<td style="width:100; background: #<%= h %>"> </td>
<td><%= c.Name %></td>
<td><%= h %></td>
<td><%= c.R %></td>
<td><%= c.G %></td>
<td><%= c.B %></td>
</tr>
<% }
} %>
</table>
</div>
<br>
<div class="header"><h3>System Colors</h3></div>
<p>The <b>KnownColor</b> enumeration also includes the collection of system colors, which represent colors that are used in a windows display element.
<div align="center">
<table class="colortable">
<tr>
<th>Color</th>
<th>Name</th>
<th>Hex Value</th>
<th>Red Value</th>
<th>Green Value</th>
<th>Blue Value</th>
</tr>
<% foreach ( KnownColor k in colors ) {
Color c = Color.FromKnownColor ( k );
if ( c.IsSystemColor ) {
string h = hex ( c ); %>
<tr>
<td style="width:100; background: <%= ColorTranslator.ToHtml ( c ) %>"> </td>
<td><%= c.Name %></td>
<td><%= h %></td>
<td><%= c.R %></td>
<td><%= c.G %></td>
<td><%= c.B %></td>
</tr>
<% }
} %>
</table>
</div>
<p>A color in ASP.NET may be specified in several ways:
<ul>
<li>by passing a color name from the <b>KnownColor</b> enumeration above, ex. <b>DarkSlateGray</b>;</li>
<li>by passing color values that denote the RGB components ( red, green, and blue ) expressed in hexadecimal format, ex. <b>#ccffaa</b>;</li>
<li>by passing color values that denote the RGB components expressed as intensity values ( 0-255 ), ex. <b>rgb ( 240, 230, 140 )</b>.</li>
<li>by passing color values that denote the RGB components expressed as percentages ( 0-100 ), ex. <b>rgb ( 25%, 50%, 75% )</b>;</li>
</ul>
<!-- <p>For more information on specifying colors, see <a href="colors.aspx">Colors and Backgrounds</a>.
-->
<p>This page uses a simple <b>Enum.GetValues</b> method to retrieve the pre-defined known colors into an array. The array is then looped thru using a simple <b>foreach</b> statement, and from each <b>KnownColor</b> object a <b>Color</b> structure is created, the values of which are extracted ( and converted to hex ), and the results dynamically generated on the page. To see how this is done, <a href="/shared/viewsrc.aspx?path=/aspnet/syntax/props/colortable.aspx.src">view source</a>. <img src="/shared/wink.gif" width="15" height="15" border=0 alt=""></p>
<div class="header"><h5>See Also</h5></div>
<p class="small">
</asp:content>