📄 checkcode.aspx.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.Drawing.Drawing2D;
namespace Com.SMS.SMSUI
{
/// <summary>
/// CheckCode 的摘要说明。
/// </summary>
public class CheckCode : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
ShowCheckCode();
}
void ShowCheckCode()
{
Response.ContentType="image/gif";
Bitmap bmp=new Bitmap(43,25);
Graphics gs=Graphics.FromImage(bmp);
gs.Clear(Color.Blue);
Font f=new Font("宋体",11,FontStyle.Bold);
// HatchBrush hbh=new HatchBrush(HatchStyle.BackwardDiagonal,Color.Red,Color.Blue);
// LinearGradientBrush lgb=new LinearGradientBrush(new Rectangle(new Point(0,0),new Size(43,25)),Color.Blue,Color.Green,45);
Point[] po={new Point(0,8),new Point(5,16),new Point(10,8),new Point(15,16),new Point(20,8),new Point(25,16),new Point(30,8),new Point(35,16),new Point(40,8)};
PathGradientBrush pgb=new PathGradientBrush(po,WrapMode.TileFlipXY);
string checkCode=new Random().Next(0,9999).ToString().PadLeft(4,'0');
Session.Add("checkCode",checkCode);
gs.DrawString(checkCode,f,pgb,4,4);
bmp.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Gif);
f.Dispose();
gs.Dispose();
bmp.Dispose();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -