How to dynamically generate validation code in asp.net

Source: Internet
Author: User

Now more and more websites like to get a verification code out, and each language can basically do, today I come to a C # write!
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;
Create a Bitmap object
public void Randomnumber ()
{
Bitmap Newbitmap = new Bitmap (36,16,PIXELFORMAT.FORMAT32BPPARGB);
Create a drawing surface from a bitmap object created above
Graphics g = graphics.fromimage (Newbitmap);
Fills the rectangular area with the specified color
G.fillrectangle (New SolidBrush (Color.White), New Rectangle (0,0,36,16));
Create a Font object
Font textfont = new Font ("Times New Roman", 10);
Create a RectangleF structure specify an area
RectangleF rectangle = new RectangleF (0,0,36,16);
Create a random Number object
Random rd = new Random ();
Get random numbers
int Valationno = 1000 + Rd. Next (8999);
Fills the rectangular area specified by the upper RectangleF structure with the specified color
G.fillrectangle (New SolidBrush (Color.burlywood), rectangle);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.