最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
如何在asp.net中动态生成验证码
时间:2008-01-12 编辑:简简单单 来源:一聚教程网
现在越来越多的网站喜欢搞个验证码出来,而且各个语言基本上都能做到,今天我来一个C#写的!
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.Imaging;
using System.Drawing.Drawing2D;
//建立位图对象
public void randomNumber()
{
Bitmap newBitmap = new Bitmap(36,16,PixelFormat.Format32bppArgb);
//根据上面创建的位图对象创建绘图面
Graphics g = Graphics.FromImage(newBitmap);
//以指定的颜色填充矩形区
g.FillRectangle(new SolidBrush(Color.White), new Rectangle(0,0,36,16));
//创建字体对象
Font textFont = new Font("Times New Roman",10);
//创建RectangleF结构指定一个区域
RectangleF rectangle = new RectangleF(0,0,36,16);
//创建随机数对象
Random rd = new Random();
//取得随机数
int valationNo = 1000 + rd.Next(8999);
//使用指定的颜色填充上面RectangleF结构指定的矩形区域
g.FillRectangle(new SolidBrush(Color.BurlyWood), rectangle);
-
上一个: 用c#写的smtp邮件发送类
相关文章
- asp.net 生成验证码源码 10-04
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10