。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
if (!Page.IsPostBack)
{
TextBox1.Focus();
ImageButton1.ImageUrl = "yanzheng.aspx";
}
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
//yanzheng.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 System.Drawing;
using System.ComponentModel;
using System.Web.SessionState;
using System.Drawing.Imaging;
public partial class admin_yanzheng : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// 在此处放置用户代码以初始化页面
/*string s = new Random().Next(1000, 10000).ToString();
Session["Code"] = s;
System.Drawing.Image img = new Bitmap(80,40);
Graphics g = Graphics.FromImage(img);
g.Clear(Color.LightBlue);
Brush brs = new SolidBrush(Color.FromArgb(0x90, 0x56, 0x89));
g.DrawString(s,
new Font("", 20),
brs,
0, 0);
Random r = new Random();
for(int i = 0; i < img.Width; i++)
{
for(int j = 0; j < img.Height; j++)
{
int scale = r.Next(100);
if(scale <= 10)
{
((Bitmap)img).SetPixel(i, j, Color.Black);
}
}
}
Response.ContentType = "image/jpg";
img.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);
Response.End();
g.Dispose();
img.Dispose();
brs.Dispose();*/
/*String code="";
Random rand = new Random();
for(int i = 0 ; i < 4; i++)
{
int num = rand.Next();
string letter = "";
switch(num % 3)
{
case 0:
letter = ((char)rand.Next(48,58)).ToString();
break;
case 1:
letter = ((char)rand.Next(65,91)).ToString();
break;
default:
letter = ((char)rand.Next(97,123)).ToString();
break;
}
code += letter;
}
Session["number"]=code;
// Response.Write(code);
// 生成图形
Bitmap bmp = new Bitmap(80,40);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
System.Drawing.Drawing2D.LinearGradientBrush b = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0,0,bmp.Width - 1 ,bmp.Height - 1),Color.Red,Color.Green,2.0F);
g.DrawString(code,new Font("宋体",24),b,0,0);
g.DrawRectangle(new Pen(Color.Blue,1),0,0,bmp.Width - 1,bmp.Height - 1);
//
// for (int i = 0 ; i < 600; i++)
// {
// int x1 = rand.Next(0,bmp.Width);
// int y1 = rand.Next(0,bmp.Height);
//
// bmp.SetPixel(x1,y1,Color.Gray);
// }
// for(int i = 0 ; i < 200; i++)
// {
// int x1 = rand.Next(0,bmp.Width);
// int y1 = rand.Next(0,bmp.Height);
// int x2 = rand.Next(0,bmp.Width);
// int y2 = rand.Next(0,bmp.Height);
//
// g.DrawLine(new Pen(Color.SeaGreen,1),x1,y1,x2,y2);
// }
Response.ContentType = "image/gif";
// bmp.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Gif);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bmp.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
Response.BinaryWrite(ms.ToArray());*/
string code = "";
Random rand = new Random();
for (int i = 0; i < 4; i++)
{
int num = rand.Next();
string letter = "";
switch (num % 3)
{
case 1:
letter = Convert.ToChar(rand.Next(48, 58)).ToString();
break;
case 2:
letter = Convert.ToChar(rand.Next(65, 91)).ToString();
break;
default:
letter = Convert.ToChar(rand.Next(97, 123)).ToString();
break;
}
code += letter;
}
//生成图形
Bitmap bmp = new Bitmap(60, 20);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.LightBlue);
Brush brush = new SolidBrush(Color.Red);
//g.DrawString(code, new Font("", 12), brush, 0, 0);
System.Drawing.Drawing2D.LinearGradientBrush b = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, bmp.Width - 1, bmp.Height - 1), Color.Red, Color.Green, 2.0F);
g.DrawString(code, new Font("黑体", 15), b, 6, 0);
//g.DrawRectangle(new Pen(Color.White, 1), 0, 0, bmp.Width - 1, bmp.Height - 1);
Response.ContentType = "image/gif";
//保存
Session["code"] = code.ToLower();
bmp.Save(Response.OutputStream, ImageFormat.Gif);
//释放资源
brush.Dispose();
g.Dispose();
bmp.Dispose();
}
}