在判斷的時候只要把取得的文字框的值與“Session["valicode"] ”進行判斷是否一致就行了。
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> //建立點陣圖物件
Bitmap NewbitMap = new Bitmap(90, 22, PixelFormat.Format32bppArgb);
//根據上面建立的位置物件建立繪圖面
Graphics g = Graphics.FromImage(NewbitMap);
//以指定的顏色填充矩形區
g.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, 90, 22));
//建立字型物件
Font newfont = new Font("幼圓", 14);
//建立RectangleF結構指定一個區域
RectangleF rectangle = new RectangleF(0, 0, 90, 22);
//建立隨機數
Random Newrd = new Random();
string[] abcd="我,是,沒,高,天,地,聊,材,盆,濁,小,涯,尖,欠,豬,左,腿,刀,吃,渴,棍,皮,影,歇,草,營,救,稅,說,壞,通,病,二,世,期,春,季,弄,刑,事,警,強,窩,菜,幹,什,前,都,哭,拉,面,魚,文,鬼,或,熱,狗,蛋,毛,筆,網,件,構,試,社,幫,耐,燒,粘,蘋,鞋,板,裳,花,海,題,a,e,f,r,9,0,k,2,4,7,1,3,q,w,y,u,v,x,p,s,a,d,8,5,t".Split(',');
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> //建立點陣圖物件
Bitmap NewbitMap = new Bitmap(90, 22, PixelFormat.Format32bppArgb);
//根據上面建立的位置物件建立繪圖面
Graphics g = Graphics.FromImage(NewbitMap);
//以指定的顏色填充矩形區
g.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, 90, 22));
//建立字型物件
Font newfont = new Font("幼圓", 14);
//建立RectangleF結構指定一個區域
RectangleF rectangle = new RectangleF(0, 0, 90, 22);
//建立隨機數
Random Newrd = new Random();
string[] abcd="我,是,沒,高,天,地,聊,材,盆,濁,小,涯,尖,欠,豬,左,腿,刀,吃,渴,棍,皮,影,歇,草,營,救,稅,說,壞,通,病,二,世,期,春,季,弄,刑,事,警,強,窩,菜,幹,什,前,都,哭,拉,面,魚,文,鬼,或,熱,狗,蛋,毛,筆,網,件,構,試,社,幫,耐,燒,粘,蘋,鞋,板,裳,花,海,題,a,e,f,r,9,0,k,2,4,7,1,3,q,w,y,u,v,x,p,s,a,d,8,5,t".Split(',');
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> int RamStr=Newrd.Next(1,100);
int Ramstr1 = Newrd.Next(1, 100);
int Ramstr2 = Newrd.Next(1, 100);
int Ramstr3 = Newrd.Next(1, 100);
string ValiNum = abcd[RamStr] + abcd[Ramstr1] + abcd[Ramstr2] + abcd[Ramstr3].ToString();
Session["valicode"] = ValiNum.ToString();
//使用指定的顏色填充上面RectangleF結構指定的矩形區域
g.FillRectangle(new SolidBrush(Color.BurlyWood), rectangle);
//繪製隨機線條
for(int ii =0;ii<10;ii++)
{
int x1=Newrd.Next(NewbitMap.Height);
int y1=Newrd.Next(NewbitMap.Width);
int x2 = Newrd.Next(NewbitMap.Height);
int y2 = Newrd.Next(NewbitMap.Width);
g.DrawLine(new Pen(Color.Azure), x1, y2, y1, x1);
}
//在上面填充的矩形區域中填充上面生成的隨機數
g.DrawString(ValiNum, newfont, new SolidBrush(Color.Blue), rectangle);
for (int i = 0; i < 50; i++)
{
int x = Newrd.Next(NewbitMap.Width);
int y = Newrd.Next(NewbitMap.Height);
NewbitMap.SetPixel(x, y, Color.FromArgb(Newrd.Next()));
}
MemoryStream ms = new MemoryStream();
NewbitMap.Save(ms, ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> int RamStr=Newrd.Next(1,100);
int Ramstr1 = Newrd.Next(1, 100);
int Ramstr2 = Newrd.Next(1, 100);
int Ramstr3 = Newrd.Next(1, 100);
string ValiNum = abcd[RamStr] + abcd[Ramstr1] + abcd[Ramstr2] + abcd[Ramstr3].ToString();
Session["valicode"] = ValiNum.ToString();
//使用指定的顏色填充上面RectangleF結構指定的矩形區域
g.FillRectangle(new SolidBrush(Color.BurlyWood), rectangle);
//繪製隨機線條
for(int ii =0;ii<10;ii++)
{
int x1=Newrd.Next(NewbitMap.Height);
int y1=Newrd.Next(NewbitMap.Width);
int x2 = Newrd.Next(NewbitMap.Height);
int y2 = Newrd.Next(NewbitMap.Width);
g.DrawLine(new Pen(Color.Azure), x1, y2, y1, x1);
}
//在上面填充的矩形區域中填充上面生成的隨機數
g.DrawString(ValiNum, newfont, new SolidBrush(Color.Blue), rectangle);
for (int i = 0; i < 50; i++)
{
int x = Newrd.Next(NewbitMap.Width);
int y = Newrd.Next(NewbitMap.Height);
NewbitMap.SetPixel(x, y, Color.FromArgb(Newrd.Next()));
}
MemoryStream ms = new MemoryStream();
NewbitMap.Save(ms, ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());