Achieve a class for a verification code
#Region to implement a verification code class
Public Class Validatecode
{
Private Bitmap ValidateImage;
Private graphics g;
Public validatecode ()
{
ValidateImage = New Bitmap (120, 30, Pixelformat.Format24bppRGB);
g = graphics.fromImage (validateImage);
}
Public Void DrawValidatecode (Page E, String i)
{
G. DrawString (I, New Font ("Black Body", 16, FontStyle.Bold, New Solidbrush (Color.White), New PointF (2, 4));
G. FillRectangle (New Lineargradientbrush (New Point (0), New Point (120, 30), Color.Fromargb (0, 0, 0), Color.Fromargb (255, 255, 255, 255)), 0, 0, 120, 30) ;
//VALIDATEIMAGE.SAVE (E.OutputStream, Imageformat.jpeg);
g.save ();
MemoryStream MS = New MemoryStream ();
ValidateImage.save (MS, System.drawing.Image.ImageFormat.gif);
E.RESPONSE.CLERCONTENT ();
E.RESPONSE.CONTENTTYPE = "image / gif";
E.RESPONSE.BINARYWRITE (Ms.Toarray ());
E.RESPONSE.END ();
//VALIDATEIMAGE.SAVE (E.MAPPATH ("NumImage/ValidateImage.gif "), Imageformat.gif);
//e.end ();
}
}
#ndregion
Private void makevalidatecode ()
{
CHAR [] S = New char [] {"0", "1", "2", "3", "4", "5", "7", "8", "9", "a"
, "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", " N "," o "," p "," q "
, "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", " D "," e "," f "," g "
, "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", " T "," u "," v "," w "," x "," y "," z "};
String Num = "";
Random r = new random ();
For (int i = 0; i <5; i )
{
Num = s [R.Next (0, S.Length)]. TOSTRING ();
}
((Loginuserinfo) session ["Loginuserinfo"]). Validatenum = NUM;
TextBox3.text = ""
}
Call the above class to successfully detect the verification code.