请问如何在C#的FORM窗口下设置验证码?
我现在只知道要用LABEL控件来显示验证码,TEXTBOX控件用来输入验证码,而后点确认的时候自动确认是否一致,不一致会给出警告。请问这个如何实现?求代码。谢谢!...
我现在只知道要用LABEL控件来显示验证码,TEXTBOX控件用来输入验证码,而后点确认的时候自动确认是否一致,不一致会给出警告。请问这个如何实现?求代码。谢谢!
展开
2个回答
2013-12-12
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace yanz
{
public partial class Form1 : Form
{
//Image img;
private string[] code;
string ViewCode = "4 3 6 6";
private string[] yecode;
//string yecode;
public Form1()
{
code = new string[4];
yecode = new string[4];
// img = (Image)Properties.Resources.验证码;
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
Font f1 = new Font("宋体", 12, FontStyle.Underline);
Brush b1 = new SolidBrush(Color.Black);
Graphics g = e.Graphics;
//di(g);
if (ViewCode == null)
{
}
else
{
//System.Diagnostics.Debug.WriteLine("Ssssss"+ViewCode);
g.DrawString(ViewCode, f1, b1, 170, 168);
}
}
public void di(Graphics e)
{
//e.DrawImage(img, 175, 165, 68, 22);
}
private void GetYZCode()
{
Random ro = new Random();
int iResult;
ViewCode = "";
for (int i = 0; i < 4; i++)
{
iResult = ro.Next(0, 10);
code[i] = iResult.ToString();
ViewCode += " " + iResult.ToString();
// MessageBox.Show(ViewCode);
}
}
private void button1_Click(object sender, EventArgs e)
{
GetYZCode();
this.Invalidate();
}
private void button2_Click(object sender, EventArgs e)
{
ViewCode=ViewCode.Replace(" ", "");
if (textBox1.Text == ViewCode)
{
MessageBox.Show("succsess");
}
else
{
MessageBox.Show("请输入正确的验证码");
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace yanz
{
public partial class Form1 : Form
{
//Image img;
private string[] code;
string ViewCode = "4 3 6 6";
private string[] yecode;
//string yecode;
public Form1()
{
code = new string[4];
yecode = new string[4];
// img = (Image)Properties.Resources.验证码;
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
Font f1 = new Font("宋体", 12, FontStyle.Underline);
Brush b1 = new SolidBrush(Color.Black);
Graphics g = e.Graphics;
//di(g);
if (ViewCode == null)
{
}
else
{
//System.Diagnostics.Debug.WriteLine("Ssssss"+ViewCode);
g.DrawString(ViewCode, f1, b1, 170, 168);
}
}
public void di(Graphics e)
{
//e.DrawImage(img, 175, 165, 68, 22);
}
private void GetYZCode()
{
Random ro = new Random();
int iResult;
ViewCode = "";
for (int i = 0; i < 4; i++)
{
iResult = ro.Next(0, 10);
code[i] = iResult.ToString();
ViewCode += " " + iResult.ToString();
// MessageBox.Show(ViewCode);
}
}
private void button1_Click(object sender, EventArgs e)
{
GetYZCode();
this.Invalidate();
}
private void button2_Click(object sender, EventArgs e)
{
ViewCode=ViewCode.Replace(" ", "");
if (textBox1.Text == ViewCode)
{
MessageBox.Show("succsess");
}
else
{
MessageBox.Show("请输入正确的验证码");
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-12-12
展开全部
主要是要比较字符串
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询