/// <summary>
/// WinFrom验证码的实现
/// </summary>
/// <param name="pictureBox1"></param>
/// <returns></returns>
public static string pictureBoxVerification(PictureBox pictureBox1) {
Random r = new Random();
string str = null;
for (int i = 0; i < 5; i++)
{
int rNumber = r.Next(0, 10);
str += rNumber;
}
//MessageBox.Show(str);
//创建GDI对象
Bitmap bmp = new Bitmap(150, 40);
Graphics g = Graphics.FromImage(bmp);
for (int i = 0; i < 5; i++)
{
Point p = new Point(i * 20, 0);
string[] fonts = { "微软雅黑", "宋体", "隶属", "仿宋", "黑体" };
Color[] colors = { Color.Yellow, Color.Red, Color.Blue, Color.Black, Color.Green };
g.DrawString(str[i].ToString(), new Font(fonts[r.Next(0, 5)], 20, FontStyle.Bold), new SolidBrush(colors[r.Next(0, 5)]), p);
}
for (int i = 0; i < 20; i++)
{
Point p1 = new Point(r.Next(0, bmp.Width), r.Next(0, bmp.Height));
Point p2 = new Point(r.Next(0, bmp.Width), r.Next(0, bmp.Height));
g.DrawLine(new Pen(Brushes.Green), p1, p2);
}
for (int i = 0; i < 500; i++)
{
Point p = new Point(r.Next(0, bmp.Width), r.Next(0, bmp.Height));
bmp.SetPixel(p.X, p.Y, Color.Black);
}
//将图片向前到PictureBox中
pictureBox1.Image = bmp;
return str;
}
WinFrom验证码的实现
猜你喜欢
转载自blog.csdn.net/qq_36074218/article/details/93633491
今日推荐
周排行