Asp.net| News | Verification Code
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);
Fills the rectangular area filled above with random numbers generated above
g.DrawString (Valationno.tostring (), Textfont, New SolidBrush (Color.Blue), rectangle);
Saves the created bitmap to the specified path
Newbitmap.save (Server.MapPath ("img") + "\\Img.gif", imageformat.gif);
}
After the build in the foreground page to introduce the image of the address on it!