Private Function generateCaptchaString()
Dim rand As New Random
Dim currentLetter As String
Dim captchaString As String = ""
For i = 0 To 6
currentLetter = ChrW(rand.Next(Asc("A"), Asc("Z") + 1))
captchaString &= currentLetter
Next
Return captchaString
End Function
'Set captchaText to what is generated in the function generateRandomString
Dim captchaText As String = generateCaptchaString()
'Creating a bitmap in memory
Dim captchaBitmap As New Bitmap(200, 40)
'Creating a Graphic so we can manipulate how the image will look
Dim captchaGraphic As Graphics = Graphics.FromImage(captchaBitmap)
Dim captchaFont As New Font("Arial", 14)
'Set the Text color
Dim captchaForeColor As New SolidBrush(Color.Blue)
'Set the background color
Dim captchaBackgroundColor As New SolidBrush(Color.Yellow)
captchaGraphic.FillRectangle(captchaBackgroundColor, 0, 0, Width, Height)
captchaGraphic.DrawString(captchaText, captchaFont, captchaForeColor, 5.0F, 5.0F)
pict_Captcha.Image = captchaBitmap
Dim captchaText As String 'I made this a global variable in case I wanted to use the captcha string elsewhere
captchaText = generalFunctions.generateCaptchaString()
If captchaText <> txt_Captcha.Text Then
'Insert error message here
End If
Copyright © 2024, NextGenUpdate.
All Rights Reserved.