c#驗證碼

來源:互聯網
上載者:User

標籤:wstring   bsp   class   awl   mes   gen   arc   ret   graph   

using System;using System.Drawing;using System.Windows.Forms;namespace aaaa{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {        }        private int count = 0;        private void Form1_Paint(object sender, PaintEventArgs e)        {        }        private void button2_Click(object sender, EventArgs e)        {//            g.DrawArc(p,new Rectangle(new Point(20,20),new Size(200,200) ),0,180);//            g.DrawRectangle(p,new Rectangle(new Point(20,20),new Size(200,100) ));//            g.DrawRectangle(p,30,30,200,200);        }        private string Obtain()        {            string str = "";            for (int i = 0; i < 4; i++)            {                var n = r.Next(10);                str += n;            }            return str;        }        private Font obtainFont(float size)        {            Font[] fonts =            {                new Font(FontFamily.GenericMonospace, size),                new Font(FontFamily.GenericSerif, size),                new Font("微軟雅黑",20f,FontStyle.Bold)            };            return fonts[r.Next(fonts.Length)];        }         private Random r = new Random();        private Color obtainColor()        {            Color[] colors = { Color.Blue, Color.Red, Color.Green };            return colors[r.Next(colors.Length)];        }        private void pictureBox1_Click(object sender, EventArgs e)        {            GetValue();        }        private void Form1_Load(object sender, EventArgs e)        {            GetValue();        }        private void GetValue()        {            var str = Obtain();            Bitmap bm = new Bitmap(100, 60);            Graphics g = Graphics.FromImage(bm);            Pen p = new Pen(Brushes.Red);            p.Width = 4;            for (int i = 0; i < str.Length; i++)            {                g.DrawString(str[i] + "", obtainFont(15), new SolidBrush(obtainColor()), new PointF(20 * i, 20));            }            var w = bm.Width;            var h = bm.Height;            for (int i = 0; i < 10; i++)            {                                g.DrawLine(new Pen(Color.Gold,2f),r.Next(w),r.Next(h),r.Next(w),r.Next(h));            }            for (int i = 0; i < 200; i++)            {                bm.SetPixel(r.Next(w),r.Next(h),Color.Magenta);            }            pictureBox1.Image = bm;        }    }}

 

c#驗證碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.