你可以用一个label窗体,用其文本窗体显示随机数,然后用textbox的文本值与lable的text值做比较下面是代码的核心部分你看一下吧,对你可能有点帮助 private static char[] constant ={'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' }; public Form1() { InitializeComponent(); } public static string GetRandomNumber(int Len) { System.Text.StringBuilder newRandom = new StringBuilder(62); Random rd = new Random(); for (int i = 0; i < Len; i++) { newRandom.Append(constant[rd.Next(62)]); } return newRandom.ToString(); } private void Form1_Load(object sender, EventArgs e) { this.label1.Text = GetRandomNumber(5); } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { this.label1.Text = GetRandomNumber(5); }