整理代码块
代码块整理后存储,供后期使用
Sub showRandomStr()
str = String.Empty
' 生成随机数字符串
Dim r As Random = New Random()
For i = 0 To 4
str += r.Next(0, 9).ToString
Next
'画字符串
Dim bmp As Bitmap = New Bitmap(120, 20)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim fonts As String() = {"宋体", "楷体", "仿宋", "草书", "华文行楷"}
Dim colors As Color() = {Color.Blue, Color.Green, Color.Red, Color.White, Color.Yellow}
For i = 0 To str.Length - 1
Dim p As Point = New Point(i * 20 + 10, 0)
g.DrawString(str(i).ToString, New Font(fonts(r.Next(0, fonts.Length)), 20), New SolidBrush(colors(r.Next(0, colors.Length))), p)
Next
'画线
For i = 0 To 20
g.DrawLine(New Pen(Color.Black), New Point(r.Next(0, bmp.Width), r.Next(bmp.Height)) _ , New Point(r.Next(0, bmp.Width), r.Next(bmp.Height)))
Next
'画点
For i = 0 To 300
bmp.SetPixel(r.Next(0, bmp.Width), r.Next(0, bmp.Height), Color.Black)
Next
pbx.Image = bmp
End Sub
标签:Dim,20,Color,代码,验证码,Next,bmp,New,绘制
From: https://www.cnblogs.com/Katakana/p/17637569.html