Captcha Creation in -- Windows Forms Application c#

Captcha  Creation   in -- Windows Forms Application c#


Have you ever wondered how to create a Captcha for your  Captcha  Creation   in  Windows Forms Application? Well, it's really simple and it won't take more than 100+ lines of code. Here what this can generate.


C#(Code)................


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 image_Capcha
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            loadCaptchimage();
        }
        int number = 0;
        private void loadCaptchimage()
        {
            Random r1 = new Random();
            number = r1.Next(100,10000);
            var image =new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
            var font = new Font("TimesNewRoman", 25, FontStyle.Italic, GraphicsUnit.Pixel);
            var grafix = Graphics.FromImage(image);
            grafix.DrawString(number.ToString(),font,Brushes.Green,new Point(0,0));
            pictureBox1.Image = image;
       
        }

        private void button2_Click(object sender, EventArgs e)
        {
            loadCaptchimage();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == number.ToString())
            {

                MessageBox.Show("Captch Match");
            }
            else
            {

                MessageBox.Show("Captcha Does not match");
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
          
        }
    }
}

Comments