⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 img.aspx.cs

📁 用asp.net开发的考试系统
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing.Imaging;

public partial class img : System.Web.UI.Page
	{
		public string vali;

		protected void Page_Load(System.Object ender, System.EventArgs e)
		{
			vali = Rndnum();
			Session["vali"] = vali;
			ValidateCode(Session["vali"].ToString());
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
		}
		#endregion

	public string Rndnum()
	{
		int j1;
		string strChoice="0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
		string [] strResult = strChoice.Split(new Char [] {','});
		string strReturn="";
		Random rnd = new Random(unchecked((int)DateTime.Now.Ticks));
		for(int i=0;i<4;i++)
		{
			Random rnd1=new Random(rnd.Next()*unchecked ((int)DateTime.Now.Ticks));
			j1=rnd1.Next(35);
			rnd=new Random (rnd.Next()*unchecked((int)DateTime.Now.Ticks));
			strReturn=strReturn + strResult[j1].ToString();
		}
		return strReturn;
	}

	public void ValidateCode(string vnum)
	{
		MemoryStream ms=new MemoryStream();
		double Height=(vnum.Length)*12;
		int gHeight=Convert.ToInt32(Height);
		Bitmap img=new Bitmap(gHeight,20);
		Graphics g=Graphics.FromImage(img);
		g.DrawString(vnum,(new Font ("Arial",10)),(new SolidBrush(Color.Red)),1,4);
		img.Save(ms,ImageFormat.Png);
		Response.ClearContent();
		Response.ContentType="images/Bmp";
		Response.BinaryWrite(ms.ToArray());
		g.Dispose();
		img.Dispose();
		Response.End();
	}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -