<%--
Pro ASP.NET Web Forms Techniques, Second Edition
By Alex Homer
ISBN: 1-59059-317-0
Published: Dec 2003
Publisher: Apress.com
--%>
<%@Page Language="C#" %>
<%@Import Namespace="System.Drawing" %>
<script runat="server">
void Page_Load() {
Color[] aKnownCols = new Color[168];
KnownColor eValue;
for (eValue = 0; eValue <= KnownColor.YellowGreen; eValue++) {
aKnownCols[(int) eValue] = Color.FromKnownColor(eValue);
}
// create a table containing the .NET colors
// declare variables, we'll create 5 rows simultaneously
TableRow oRow1, oRow2, oRow3, oRow4, oRow5;
TableCell oCell;
Color oKnown;
String sDecimalVals, sHexVals, sKnown;
int iCellCount = 0;
// to create empty cell with colored background
String sColorCell = "<font size=5> </font>";
// create empty Table object and five Row objects
Table oTable = new Table();
oRow1 = new TableRow();
oRow2 = new TableRow();
oRow3 = new TableRow();
oRow4 = new TableRow();
oRow5 = new TableRow();
// set horizontal alignment for three rows
oRow2.HorizontalAlign = HorizontalAlign.Center;
oRow3.HorizontalAlign = HorizontalAlign.Center;
oRow4.HorizontalAlign = HorizontalAlign.Center;
// iterate through array of safe colors
foreach (Color oColor in aKnownCols) {
iCellCount += 1; // increment cell counter
// create the strings showing decimal and hex RGB values
sDecimalVals = oColor.R.ToString() + "," + oColor.G.ToString()
+ "," + oColor.B.ToString();
sHexVals = "#" + oColor.R.ToString("x2") + oColor.G.ToString("x2")
+ oColor.B.ToString("x2");
sKnown = oColor.Name;
// create a new cell, and add LiteralControl containing value
oCell = new TableCell();
oCell.Controls.Add(new LiteralControl(sColorCell));
// set properties for this cell, and add to row 1
oCell.BorderColor = Color.Black;
oCell.BorderStyle = BorderStyle.Solid;
oCell.BorderWidth = Unit.Pixel(1);
oCell.BackColor = oColor;
oRow1.Cells.Add(oCell);
// repeat for cells containing decimal, hex and color name values
oCell = new TableCell();
oCell.Controls.Add(new LiteralControl(sDecimalVals));
oRow2.Cells.Add(oCell);
oCell = new TableCell();
oCell.Controls.Add(new LiteralControl(sHexVals));
oRow3.Cells.Add(oCell);
oCell = new TableCell();
oCell.Controls.Add(new LiteralControl(sKnown));
oRow4.Cells.Add(oCell);
// create cell in row 5 to provide space between color rows
oCell = new TableCell();
oCell.Controls.Add(new LiteralControl(" "));
oRow5.Cells.Add(oCell);
// start a new row every eight values
if ((int)(iCellCount / 8) == ((float)iCellCount / 8)) {
oTable.Rows.Add(oRow1);
oTable.Rows.Add(oRow2);
oTable.Rows.Add(oRow3);
oTable.Rows.Add(oRow4);
oTable.Rows.Add(oRow5);
oRow1 = new TableRow();
oRow2 = new TableRow();
oRow3 = new TableRow();
oRow4 = new TableRow();
oRow5 = new TableRow();
oRow2.HorizontalAlign = HorizontalAlign.Center;
oRow3.HorizontalAlign = HorizontalAlign.Center;
oRow4.HorizontalAlign = HorizontalAlign.Center;
}
}
ctlPlaceholder.Controls.Add(oTable);
}
</script>
<html>
<head>
<title>.NET Standard Color Names</title>
</head>
<body>
<span class="heading">.NET Standard Color Names</span><p />
<asp:PlaceHolder id="ctlPlaceholder" runat="server" />
</body>
</html>
|