This Simple Captcha Application doesn't need Internet to load it's Captcha but it generates a random image for you to answer.
Picture: http://cur.lv/4q76m
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.
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.
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.
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.
Support here: http://forum.nsst.co/threads/egyszer%C5%B1-captcha-alkalmaz%C3%A1s-simple-captcha-application.19/