namespace 画验证码
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
Random r = new Random();
string strNum = "";
for (int i = 0; i < 5; i++)
{
int num = r.Next(10);
strNum += num;
}
Bitmap bm = new Bitmap(150,50);
Graphics g = Graphics.FromImage(bm);
string[] font = new string[] {"幼圆","华文行楷","全新硬笔行书简","楷体","黑体" };
Color[] color = new Color[] {Color.Red,Color.Blue,Color.Green,Color.PaleGreen,Color.Black };
for (int i = 0; i < 5; i++)
{
Point point=new Point(i*20, 0);
g.DrawString(strNum[i].ToString(), new Font(font[i], 20), new SolidBrush(color[i]), point);
Point p_1 = new Point(r.Next(bm.Width), r.Next(bm.Height));
Point p_2 = new Point(r.Next(bm.Width), r.Next(bm.Height));
g.DrawLine(new Pen(color[i]), p_1, p_2);
}
}
}
}
|