c#产生随机颜色

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        string k = getStrColor();
       
        Label1.ForeColor=System.Drawing.Color.FromName( getStrColor());

      // Label1.ForeColor=Color.FromArgb(random.Next(255),random.Next(255),random.Next(255));

    }
    private static Random rand = new Random();

    public static string getStrColor()
    {
        Color color = Color.FromArgb(rand.Next());
        string strColor = "#" + Convert.ToString(color.ToArgb(), 16).PadLeft(8, '0').Substring(2, 6);
        return strColor;
    }
  
}

posted @ 2011-01-21 09:39  .雷子.  阅读(1083)  评论(0编辑  收藏  举报
投入到.net、web前端开发、继续学习!