日期:2014-05-17 浏览次数:21223 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace RandomCode
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Random rd;
private int gg;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics gh = e.Graphics;
rd = new Random();
gg = rd.Next(1000, 10000);
Font font = new Font(FontFamily.Families[5], 10);
SolidBrush brush = new SolidBrush(Color.SandyBrown);
gh.DrawString(gg.ToString(),font,brush, 0, 0);
}
private void Draw_Click(object sender, EventArgs e)
{
Rectangle rc = new Rectangle(0,0,40,20);
this.Invalidate(rc);
}
private void Check_Click(object sender, EventArgs e)
{
try
{
if (gg != Convert.ToInt32(message.Text.Trim()))
{
MessageBox.Show("请输入正确的验证码");
}
}
catch (FormatException exp)
{
MessageBox.Show(exp.Message);
}
}
}
}