资源简介

winform简单用户登录(带验证码)

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DrawCheckCode
{
    public partial class Form1 : Form
    {
        private static string CheckCode;
        private static bool Lock=true; 
        public Form1()
        {
            InitializeComponent();
            pictureBox2.Image = Image.FromFile(@“..\..\Img\ICO\Key3.ico“);
            CheckCode = CreateCheckCode();
            CodeImg(CheckCode);
        }
        //生成随机数
        private string CreateCheckCode()
        {
            int num;
            char code;
            string  CheckCode = string.Empty;
            Random r = new Random();
            for (int i = 0; i < 6; i++)
{
                num = r.Next();
                if (num%2 == 0)
                {
                    code = (char)(‘0‘ + (char)(num % 10));
                }
                else
                {
                    code = (char)(‘A‘ + (char)(num % 26));
                }
                CheckCode += code;
}
            return CheckCode;
        }

        //写入图片
        private void CodeImg(string CheckCode)
        {
            if (string.IsNullOrEmpty(CheckCode))
            {
                return;
            }
            Bitmap img=new Bitmap((int)Math.Ceiling((CheckCode.Length*11.1))22);
            Graphics g = Graphics.FromImage(img);
            try
            {
                Random random = new Random();
                g.Clear(Color.White);
                for (int i = 0; i < 3; i++)
                {
                    int x1 = random.Next(img.Width);
                    int x2 = random.Next(img.Width);
                    int y1 = random.Next(img.Height);
                    int y2 = random.Next(img.Height);
                    g.DrawLine(new Pen(Color.Black) x1 y1 x2 y2);
                }
                Font ft = new Font(“Arial“ 12 Fontstyle.Bold);
                g.DrawString(CheckCode ft new SolidBrush(Color.Red) 2 2);
                for (int i = 0; i < 150; i++)
                {
                    int x = random.Next(img.Width);
                    int y = random.Next(img.Height);
                    img.SetPixel(xyColor.FromArgb(random.Next()));
                }
                g.DrawRectangle(new Pen(Color.Silver)00img.Width-1img.Height-1);
                this.pictureBox1.Width=img.Width;
                this.pictureBox1.Height=img.Height;
                this.pictureBox1.BackgroundImage=img; 

            }
            catch (Exception)
            {
                
                throw;
            }
        
        
        }
        //刷新
        private void button1_Click(object sender EventArgs e)
        {
            CheckCode = CreateCheckCode();
            CodeImg(CheckCode);
        }
        //点

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        825  2020-09-30 11:46  DrawCheckCode\app.config

     文件      26624  2020-09-30 15:37  DrawCheckCode\bin\Debug\DrawCheckCode.exe

     文件        825  2020-09-30 11:46  DrawCheckCode\bin\Debug\DrawCheckCode.exe.config

     文件      56832  2020-09-30 15:37  DrawCheckCode\bin\Debug\DrawCheckCode.pdb

     文件      14328  2020-09-30 15:37  DrawCheckCode\bin\Debug\DrawCheckCode.vshost.exe

     文件        825  2020-09-30 11:46  DrawCheckCode\bin\Debug\DrawCheckCode.vshost.exe.config

     文件        490  2009-06-11 05:14  DrawCheckCode\bin\Debug\DrawCheckCode.vshost.exe.manifest

     文件     325632  2017-06-12 09:27  DrawCheckCode\bin\Debug\Newtonsoft.Json.Net35.dll

     文件        109  2020-09-30 14:30  DrawCheckCode\Data\1

     文件       4671  2020-09-30 15:15  DrawCheckCode\DrawCheckCode.csproj

     文件       5289  2020-09-30 15:39  DrawCheckCode\Form1.cs

     文件       7882  2020-09-30 15:38  DrawCheckCode\Form1.Designer.cs

     文件       6893  2020-09-30 15:38  DrawCheckCode\Form1.resx

     文件        742  2020-09-30 15:21  DrawCheckCode\Frm_Main.cs

     文件       9013  2020-09-30 15:21  DrawCheckCode\Frm_Main.Designer.cs

     文件       9207  2020-09-30 15:21  DrawCheckCode\Frm_Main.resx

     文件        766  2000-03-27 15:44  DrawCheckCode\Img\ICO\0++.ico

     文件        766  2000-03-27 15:43  DrawCheckCode\Img\ICO\0.ico

     文件        766  2000-03-27 15:45  DrawCheckCode\Img\ICO\1++.ico

     文件       2238  2000-03-27 16:13  DrawCheckCode\Img\ICO\1+.ico

     文件        766  2000-03-27 15:43  DrawCheckCode\Img\ICO\1.ico

     文件        766  2000-03-27 15:45  DrawCheckCode\Img\ICO\2++.ico

     文件        766  2000-03-27 15:43  DrawCheckCode\Img\ICO\2.ico

     文件        766  2000-03-27 15:45  DrawCheckCode\Img\ICO\3++.ico

     文件        766  2000-03-27 15:44  DrawCheckCode\Img\ICO\3.ico

     文件        766  2000-03-18 10:55  DrawCheckCode\Img\ICO\3D.ico

     文件        766  1997-06-22 18:07  DrawCheckCode\Img\ICO\3Dimpact.ico

     文件        766  2000-03-27 15:45  DrawCheckCode\Img\ICO\4++.ico

     文件        766  2000-03-27 15:44  DrawCheckCode\Img\ICO\4.ico

     文件        766  2000-03-27 15:45  DrawCheckCode\Img\ICO\5++.ico

............此处省略505个文件信息

评论

共有 条评论