今天遇到選擇顏色的難題,不知道C#的顏色那個合適,試了幾個都不合適,因而,忽然想到反射,因而就在web下將Color下的顏色所有都列舉出來,代碼以下html
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:Panel ID="Panel1" runat="server">
- </asp:Panel>
- </div>
- </form>
- </body>
- </html>
- using System;
- using System.Drawing;
- using System.Reflection;
- using System.Web.UI.WebControls;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- Type t = Color.Aqua.GetType();
- PropertyInfo[] minfos = t.GetProperties();
- foreach ( var m in minfos)
- {
- Label l = new Label();
- l.Text = m.Name + "<br/>";
- if (Color.FromName(m.Name).IsKnownColor)
- {
- l.ForeColor = Color.FromName(m.Name);
- Panel1.Controls.Add(l);
- }
- }
- }
- }
而後你們能夠根據本身須要選擇本身想要的顏色了~web