Simple Captcha Application

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
4 posts Page 1 of 1
Contributors
User avatar
3aaBrSbeel
Top Poster
Top Poster
Posts: 139
Joined: Fri Jun 01, 2012 9:34 am

Simple Captcha Application
3aaBrSbeel
This Simple Captcha Application doesn't need Internet to load it's Captcha but it generates a random image for you to answer.

Screeny:
3-30-2013 10-44-35 AM.png
Okay, you need the following elements:
  • 2 Button
    1 PictureBox
    1 TextBox
Button 1 will be the Submit button. Checking if the answer is correct or incorrect.
Button 2 will be the one refreshing a new generated image for you to answer.
TextBox you need this to answer lmao;
PictureBox you need this to show the image lmao;

Okay, let's start. Add this code below your Public Class.
This code will create the question and the lines so it's a bit harder to read which makes it a bit challenging.
Code: Select all
    Private cAnswer As String = Nothing

    Private Function genQuestion() As String
        Dim cOperators As String() = {"+", "-"}
Start:
        Dim p1 As Integer = New Random().Next(1, 9)
        Dim p2 As Integer = New Random().Next(1, 9)

        If p1 = p2 Then GoTo Start

        Dim cOperator As String = cOperators(New Random().Next(0, cOperators.Length))

        Select Case cOperator
            Case "+"
                cAnswer = p1 + p2
                If cAnswer <= 0 Then GoTo Start
            Case "-"
                cAnswer = p1 - p2
                If cAnswer <= 0 Then GoTo Start
        End Select
        Return String.Format("{0}{1}{2}", p1, cOperator, p2)
    End Function
    Private Sub generateLines(ByVal G As Graphics)
        If Not G Is Nothing Then
            Dim R As New Random()
            Dim lineBrush As New SolidBrush(Color.LightGray)

            For i% = 0 To 9
                G.DrawLines(New Pen(lineBrush, R.Next(1, 2)), New Point() {New Point(0, R.Next(0, 60)), New Point(200, R.Next(0, 60))})

            Next
        End If
    End Sub

    Private Function generateImage() As Image
        Dim B As New Bitmap(200, 60)
        Using G As Graphics = Graphics.FromImage(B)
            With G
                .Clear(Color.White)
                .DrawString(genQuestion(), New Font("Segoe UI", 20), Brushes.Black, New Rectangle(0, 0, 200, 60), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
            End With
            generateLines(G)
        End Using
        Return B
    End Function
So next, we will be coding the submit button or Button 1, this will submit your answer. lmao;
Code: Select all
Select Case TextBox1.Text
            Case Is = cAnswer

                MessageBox.Show("Correct!", "Correct!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
                PictureBox1.Image = generateImage()
                TextBox1.Clear()
            Case Else
                MessageBox.Show("Incorrect!", "Incorrect!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
                PictureBox1.Image = generateImage()
                TextBox1.Clear()
        End Select
        TextBox1.Clear()
Button 2 and Form_Load will be the same code. Add this line of code to Button 2 and Form_Load.
Code: Select all
PictureBox1.Image = generateImage()
When you are done, debug it and test. Thanks for reading and testing this thread, I'm pretty sure you've learned something new.
You do not have the required permissions to view the files attached to this post.
Code'n'Stuff Signature Of 3aaBrSbeel
®║▌│█│║▌║││█║▌║▌║▌
✔ Verified Official Code'n'Stuff account ᵀᴴᴱ ᴼᴿᴵᴳᴵᴻᴬᴸ
Image
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: Simple Captcha Application
Shim
nice one mate , keep it up
Find my programs on Softpedia
User avatar
benji_19994
VIP - Donator
VIP - Donator
Posts: 156
Joined: Mon Apr 16, 2012 3:13 pm

Re: Simple Captcha Application
benji_19994
It looks heaps like this did you copy and paste it? you should give the credits to the author

http://www.hackforums.net/showthread.php?tid=3365830
User avatar
master3395
New Member
New Member
Posts: 14
Joined: Wed May 08, 2013 8:17 pm

Re: Simple Captcha Application
master3395
benji_19994 wrote:
It looks heaps like this did you copy and paste it? you should give the credits to the author

http://www.hackforums.net/showthread.php?tid=3365830
Both was made at the same time, might be the same owner.

This was made

Postby 3aaBrSbeel » Sat Mar 30, 2013 3:54 am

And the one on the other site was made

03-30-2013, 03:45 AM (This post was last modified: 03-30-2013 03:50 AM by Hexology.)

Might be the same owner.
4 posts Page 1 of 1
Return to “Tutorials”