winfrom中该怎么写验证码程序?求大神..
在写过,但是转到winfrom就不会了,对vs不是很熟,一直提示缺少using引用,求大神
你使用的是验证码控件么?自己写的话应该引用这个命名空间using System.Drawing.Imaging;
using System.Drawing; using System.Drawing.Drawing2D; public static string CreateCode(int codeLength) { const string codes = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,j,k,m,n,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,J,K,M,N,P,Q,R,S,T,U,V,W,X,Y,Z"; var strArr = codes.Split(','); var result = ""; var random = new Random((int) DateTime.Now.Ticks); for (var i = 0; i < codeLength; i++) result += strArr[random.Next(0, strArr.Length)]; return result; } public static Bitmap CreateImages(string code) { var result = new Bitmap(120, 36); var g = Graphics.FromImage(result); g.Clear(Color.Khaki); var random = new Random((int)DateTime.Now.Ticks); for (var i = 0; i < 12; i++) { var x1 = random.Next(result.Width); var x2 = random.Next(result.Width); var y1 = random.Next(result.Height); var y2 = random.Next(result.Height); g.DrawLine(new Pen(Color.Black), x1, y1, x2, y2); } var font = new Font("Arial", 25, FontStyle.Bold | FontStyle.Italic); var lgb = new LinearGradientBrush( new Rectangle(0, 0, result.Width, result.Height), Color.Gray, Color.Black, 1.2f, true); g.DrawString(code, font, lgb, 0, 0); for (var i = 0; i < 10; i++) { var x = random.Next(result.Width); var y = random.Next(result.Height); result.SetPixel(x, y, Color.Black); } g.DrawRectangle(new Pen(Color.DimGray), 0, 0, result.Width - 1, result.Height - 1); return result; }