valitionno.aspx.cs
来自「asp.net专家200问(含源代码解决法案」· CS 代码 · 共 68 行
CS
68 行
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;
namespace CommonFunction.test
{
/// <summary>
/// ValitionNO 的摘要说明。
/// </summary>
public class ValitionNO : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Image Image1;
private void Page_Load(object sender, System.EventArgs e)
{
//建立位图对象
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);
//在上面填充的矩形区域中填充上面生成的随机数
g.DrawString(valationNo.ToString(), textFont, new SolidBrush(Color.Blue), rectangle);
//把创建的位图保存到指定的路径
newBitmap.Save(Server.MapPath("img")+"\\VaImg.gif", ImageFormat.Gif);
}
#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 + =
减小字号Ctrl + -
显示快捷键?