添加验证码

时间:2018-04-04 20:42:29

标签: c# string

我正在尝试为我的项目创建一个注册表单,我遇到了以下问题: 我正在尝试添加验证码。我有10张带代码的图片(例如“8otes”),我想将输入与图片名称进行比较。每张图片都是由代码绘制的。这是我的代码的一部分:

string captchaImg = "";
Random random = new Random();
captcha = random.Next(1, 11);
switch (captcha)
                {
                    case 1:
                        pictureBox2.ImageLocation = "C:\\...\\8otes.png";
                        captchaImg = "8otes";
                        break;
                    case 2:
                        pictureBox2.ImageLocation = "C:\\...\\6faf3.png";
                        captchaImg = "6faf3";
                        break;
                    case 3:
                        pictureBox2.ImageLocation = "C:\\...\\06453.png";
                        captchaImg = "06453";
                        break;
                }
if (textBox6.Text != captchaImg)
   MessageBox.Show("Incorrect Captcha");
else
   //execute code

1 个答案:

答案 0 :(得分:0)

我弄清楚问题是什么。在检查之前代码和图片是否更改(textBox6.Text!= captchaImg)。我所要做的就是在更改图片和captchaImg的值之前检查是否(textBox6.Text!= captchaImg)。