All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP5,OOP编程之代理与定制异常_php资料_编程技术
C#教程:DLL动态链接库的故障排除工具
C#中CheckedListBox控件应用实例
ASP.NET编程入门随想之信客_[Asp.Net教程]
Linux+MYSQL+Apache+PHP的安装_php资料_编程技术
实例:PHP生成word文档格式试卷的代码_php资料_编程技术
delphi动作列表组件(TActionList)使用实例
ASP.NET,2.0,中好东西(theme)介绍_[Asp.Net教程]
全面解读垂直搜索引擎_php资料_编程技术
SQL,Server,2000企业版安装教程_mssql学习_编程技术
Reading number is top 10 pictures
人美胸美腿更美4
The dog buy the ham oneself
NeedWallpaper7
Small QiShu -- ShuangShuangPan1
The little girl with long hair3
Born After 90 Beijing sports university campus flower photos5
Average female college students2
看到这个手速,决定过年就让我家猫帮我抢红包了。。
Summer is most suitable for young people to travel in China8
The service WaLiangGe Chinese aircraft carrier1
Download software ranking
matrix1
asp.netWeb服务器高级编程
美女写真1
jdk1.6 for windows
株洲本地在线棋牌游戏
VC++6.0培训教程
Boxer Classic video3
功夫熊猫2(下集)
The Bermuda triangle2
Proficient in Eclipse
delv published in(发表于) 2014/1/24 9:04:13 Edit(编辑)
asp.net2.0生成验证码,并显示验证码_[Asp.Net教程]

asp.net2.0生成验证码,并显示验证码_[Asp.Net教程]

asp.net2.0生成验证码,并显示验证码_[Asp.Net教程]

1、建立网站,添加一个网页ValitionNo.aspx,和Default.aspx,新建一个文件夹images。如图所示:

2、ValitionNo.aspx里不用放任何控件,代码如下:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ValitionNo.aspx.cs" Inherits="guestBook_ValitionNo" %>





无标题页













  双击页面ValitionNo.aspx进入ValitionNo.aspx.cs页面,按如下所示填充代码:


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.Imaging;
using System.Drawing.Drawing2D;
using System.Drawing;

public partial class guestBook_ValitionNo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

Random rd = new Random(); //创建随机数对象
int valationNo = 1000 + rd.Next(8999);//取得4位随机数

//建立位图对象
Bitmap newBitmap = new Bitmap(34, 16, PixelFormat.Format32bppArgb);
//根据上面创建的位图对象创建绘图面
Graphics g = Graphics.FromImage(newBitmap);
//以指定的颜色填充矩形区
g.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, 34, 16));

//创建字体对象
Font textFont = new Font("Times New Roman", 10);

//创建RectangleF结构指定一个区域
RectangleF rectangle = new RectangleF(6, 0, 34, 16);

//使用指定的颜色填充上面RectangleF结构指定的矩形区域
g.FillRectangle(new SolidBrush(Color.BurlyWood), rectangle);
//在上面填充的矩形区域中填充上面生成的随机数
g.DrawString(valationNo.ToString(), textFont, new SolidBrush(Color.Blue), rectangle);
//把创建的位图保存到指定的路径
newBitmap.Save(Server.MapPath("images") + "\VaImg.gif", ImageFormat.Gif);
newBitmap.Save(Response.OutputStream, ImageFormat.Gif);
}
}



3、在Default.aspx里添加一个图片按钮和普通按钮,ImageButton的图片路径是~/ValitionNo.aspx,而不是某张图片。代码如下:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>





无标题页





验证码:






在Default.aspx.cs里不用添任何额外代码。Default.aspx.cs代码如下:


using System;
using System.Data;
using System.Configuration;
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;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
}


4、运行效果如下所示:

如果点验证码图片或者点换一张按钮,都可以使验证码的数字随机改变。







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.