char[] s = new char[]{'0','1', '2','3','4','5','6','7','8','9','a'
 ,'b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q'
 ,'r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G'
 ,'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W'
 ,'X','Y','Z'};
string num="";
Random r = new Random();
for(int i = 0; i < 5; i++)
{
num += s[r.Next(0,s.Length)].ToString(); 
}
return num;
这是个随机的验证码函数,你自己修改下就可以了

解决方案 »

  1.   

    TO:fds2003(Hunter) 错误提示:
    Form1.cs(123): 由于“WindowsApplication9.Form1.button1_Click(object, System.EventArgs)”返回 void,返回关键字后面不得有对象表达式
      

  2.   

    结合fds2003给的函数,和忽悠大师的要求,我把可以直接运行的源程序贴出来:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace WindowsApplication4
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Button button1;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.label1 = new System.Windows.Forms.Label();
    this.button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // label1
    // 
    this.label1.Location = new System.Drawing.Point(40, 40);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(200, 24);
    this.label1.TabIndex = 0;
    this.label1.Text = "label1";
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(96, 152);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(96, 32);
    this.button1.TabIndex = 1;
    this.button1.Text = "button1";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.Add(this.button1);
    this.Controls.Add(this.label1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    }
    public static string GetNum()
    {
    string[] s = new string[]{"0","1","2","3","4","5","6","7","8" ,"9","10"};

    string num="";
    Random r = new Random();
    num += s[r.Next(0,s.Length)].ToString(); 
    return num;
    } private void button1_Click(object sender, System.EventArgs e)
    {
    label1.Text=Form1.GetNum();
    } }
    }
      

  3.   

    for(Num=1;Num<=10;Num++)
    {
    label1.Text =Num.ToString ();
    }循环结束自然是10啦!要用随机变量
      

  4.   

    for(Num=1;Num<=10;Num++)
    {
    label1.Text =Num.ToString ();
    }
    每1次循环 label1.Text 都得到一个值,循环结束了,最后得到的是10,结果当然是10咯
      

  5.   

    首先先谢谢xiongchen(二氧化鬼) 其次 如果我想在label1中循环显示1-10这几个数怎么写呢?
      

  6.   


    private void button1_Click(object sender, System.EventArgs e)
    {
    int Num=0;
    string s=""
    for(Num=1;Num<=10;Num++)
    {
     s=s+Num.ToString ();
    }
    label1.Text=s
    }
      

  7.   

    To: luanlan02(蓝枫) 
    你的代码是把Num 的值全部显示出来,而不是一个一个的显示我想实现的是点击一次出现一个数值 :)
      

  8.   

    谢谢各位,恭祝各位新年快乐!!To: fds2003(Hunter)   xiongchen(二氧化鬼)  luanlan02(蓝枫)
    请到这里领分:
    http://community.csdn.net/Expert/topic/3780/3780289.xml?temp=.32745