實現代碼如下 :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CodeClassLibrary;
using System.IO;
using System.Net;
namespace ValidatorCodeDemo
{
public partial class frmValidatorCode : Form
{
public frmValidatorCode()
{
InitializeComponent();
this.GetCode();
}
private void btnRefresh_Click(object sender, EventArgs e)
{
this.GetCode();
}
/// <summary>
/// 產生新的驗證碼
/// </summary>
private void GetCode()
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://checkcode.taobao.com/auction/checkcode?sessionID=eb3f99fbe975258ea87bc24c235ab24f&r=1237173457015");
Stream responseStream = ((HttpWebResponse)request.GetResponse()).GetResponseStream();
Image original = Image.FromStream(responseStream);
Bitmap bitMap = new Bitmap(original);
this.pBoxCode.Image = bitMap; //注意:替換為你的PictureBox控件名字
responseStream.Close();
}
catch (Exception exception)
{
MessageBox.Show("ERROR:" + exception.Message);
}
}
}
}