Random verification code,
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Linq;
Using System. Text;
Using System. Threading. Tasks;
Using System. Windows. Forms;
Namespace GDI _
{
Public partial class: Form
{
Public letter ()
{
InitializeComponent ();
}
// Implement Random verification codes in WinForm
Private void picturebox#click (object sender, EventArgs e)
{
// Define the canvas size
Bitmap bmp = new Bitmap (100,100 );
// Define a variable
String str = "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
Random r = new Random (); // randomly generated
String newstr = "";
For (int I = 0; I <6; I ++)
{
Newstr + = str [r. Next (0, 62)];
}
Graphics g = Graphics. FromImage (bmp );
// Random font
String [] fname = {"", ""};
// Random color
Color [] color = {Color. Red, Color. Green, Color. Pink, Color. Yellow, Color. Gold, Color. Black };
For (int I = 0; I <newstr. Length; I ++)
{
Point p = new Point (I * 15, 20 );
G. drawString (newstr [I]. toString (), new Font (fname [r. next (0, 6)], 18, FontStyle. italic), new SolidBrush (color [r. next (0, 6)]), p );
}
// The background noise line of the picture on the Verification Code
For (int I = 0; I <15; I ++)
{
G. drawLine (new Pen (color [r. next (0, 6)]), new Point (r. next (1, 0,100), r. next (0,100), new Point (r. next (1, 0,100), r. next (0,100 )));
}
// The background noise of the image on the Verification Code
For (int I = 0; I <300; I ++)
{
Bmp. SetPixel (r. Next (0,100), r. Next (0,100), color [r. Next (0, 6)]);
}
This. pictureBox1.Image = bmp;
}