using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
namespace Colors
{
/// <summary>
/// ColorTable 的摘要说明
/// </summary>
public class ColorTable : System.Web.UI.UserControl
{
public ColorTable()
{
}
public override void RenderControl(HtmlTextWriter writer)
{
KnownColor[] colors = Enum.GetValues(typeof(KnownColor)) as KnownColor[];//#123456
writer.Write("<center><div style='width:500px'>");
foreach (KnownColor str in colors)
{
writer.Write("<input type='button' onClick='f(this)' style='height:20px; width:30px; background-color:" + str.ToString() + "' />");
}
writer.Write("</div></center>");
string javascript = "function f(e){document.body.bgColor = e.style.backgroundColor;}";
Page.ClientScript.RegisterStartupScript(this.GetType(), "code", javascript, true);
base.RenderControl(writer);
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/QQlvbo/archive/2009/01/04/3706712.aspx