<%@ Import namespace="System.Drawing" %>
<html>
<head>
<title>WebControl ForeColor and BackColor Properties Example</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void Page_Load ( Object src, EventArgs e ) {
if ( !IsPostBack ) {
Array colors = Enum.GetValues ( typeof ( KnownColor ) );
ListItemCollection f = ForecolorSelect.Items, b = BackcolorSelect.Items;
foreach ( KnownColor k in colors ) {
Color c = Color.FromKnownColor ( k );
if ( !c.IsSystemColor ) {
f.Add ( c.Name ); b.Add ( c.Name );
}
}
f.FindByValue ( "Navy" ).Selected = true;
b.FindByValue ( "Khaki" ).Selected = true;
}
thePanel.ForeColor = Color.FromName ( ForecolorSelect.SelectedItem.Text );
thePanel.BackColor = Color.FromName ( BackcolorSelect.SelectedItem.Text );
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>Dynamically Setting the ForeColor and BackColor Properties of a Web Control</h2></div>
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<asp:panel id="thePanel" runat="server" width=80%
style="font: bold 11pt; padding:10"
borderstyle="inset" borderwidth=1>
<p>Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation or any nation so conceived and so dedicated can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field as a final resting-place for those who here gave their lives that that nation might live. </p>
</asp:panel>
<p>
ForeColor: <asp:dropdownlist id="ForecolorSelect" autopostback runat="server" />
BackColor: <asp:dropdownlist id="BackcolorSelect" autopostback runat="server" />
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>