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
This Simple Captcha Application doesn't need Internet to load it's Captcha but it generates a random image for you to answer.
Screeny: Okay, you need the following elements:
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.
Screeny: Okay, you need the following elements:
- 2 Button
1 PictureBox
1 TextBox
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
So next, we will be coding the submit button or Button 1, this will submit your answer. lmao;
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
Code: Select all
Button 2 and Form_Load will be the same code. Add this line of code to Button 2 and Form_Load.
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()
Code: Select all
When you are done, debug it and test. Thanks for reading and testing this thread, I'm pretty sure you've learned something new.PictureBox1.Image = generateImage()
You do not have the required permissions to view the files attached to this post.
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
http://www.hackforums.net/showthread.php?tid=3365830
benji_19994 wrote:It looks heaps like this did you copy and paste it? you should give the credits to the authorBoth was made at the same time, might be the same owner.
http://www.hackforums.net/showthread.php?tid=3365830
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
Copyright Information
Copyright © Codenstuff.com 2020 - 2023