zoukankan      html  css  js  c++  java
  • c#验证码

    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;
            }
        }
    }
  • 相关阅读:
    netcore使用IdentityServer在nginx下502错误的解决
    更新到.netcore3.0后找不到dotnet-ef的解决办法
    openssh-win64 on windows2016 ssh pub key config
    405 Method Not Allowed error with PUT or DELETE Request on IIS Server
    minikube windows hyperx填坑记
    angular当router使用userhash:false时路由404问题
    内网gitlab11.2升级至11.4.5
    Angular7上手体验
    动态规划之背包问题
    Union-Find算法详解
  • 原文地址:https://www.cnblogs.com/zhaoxianglong1987/p/7623592.html
Copyright © 2011-2022 走看看