How to dynamically generate a verification code in asp.net

Source: Internet
Author: User


More and more websites now like to develop verification codes, which can be basically achieved in all languages. Today I am writing a 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;
// Create a bitmap object
Public void randomNumber ()
{
Bitmap newBitmap = new Bitmap (36,16, PixelFormat. Format32bppArgb );
// Create a drawing surface based on the previously created bitmap object
Graphics g = Graphics. FromImage (newBitmap );
// Fill the rectangle with the specified color
G. FillRectangle (new SolidBrush (Color. White), new Rectangle ));
// Create a font object
Font textFont = new Font ("Times New Roman", 10 );
// Create a RectangleF structure to specify a region
RectangleF rectangle = new RectangleF (0, 0, 36, 16 );
// Create a random number object
Random rd = new Random ();
// Obtain a random number
Int valationNo = 1000 + rd. Next (8999 );
// Fill the area of the rectangle specified by the 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.