asp.net|驗證碼
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;
using System.Drawing.Imaging;
using System.Drawing.Text;
public class RandPic:System.Web.UI.Page
{
/// <summary>
/// 驗證碼數字
/// </summary>
public int Num = 0;
/// <summary>
/// 圖片寬度
/// </summary>
public int ImgWidth=60;
/// <summary>
/// 圖片高度
/// </summary>
public int ImgHeight=30;
public RandPic()
{
}
/// <summary>
/// 建構函式
/// </summary>
/// <param name="RndNum">驗證碼數字</param>
public RandPic(int RndNum)
{
if (RndNum > 0)
{
Num = RndNum;
}
}
/// <summary>
/// 產生圖片
/// </summary>
public void Make()
{
Bitmap map=new Bitmap(ImgWidth,ImgHeight);
Graphics gp = Graphics.FromImage(map);
gp.Clear(Color.White);
Font ft = new Font("Arial Black", 13);
PointF point =new PointF(3,3);
gp.DrawString(Num.ToString(), ft, Brushes.BurlyWood, point);
gp.Save();
map.Save(Response.OutputStream, ImageFormat.Gif);
}
}
調用頁 showRand.aspx
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 _14Base;
public partial class Manager_LogRnd : RandPic
{
protected void Page_Load(object sender, EventArgs e)
{
this.Num = 8888;
HttpCookie cookie = new HttpCookie("UserRnd", rnd.ToString());
Response.Cookies.Add(cookie);
this.Make();
}
}