加一个ErrorProvider
this.errorProvider1.ContainerControl = this;
this.errorProvider1.SetIconAlignment(this.textBox1, System.Windows.Forms.ErrorIconAlignment.MiddleRight);
this.errorProvider1.SetIconPadding(this.textBox1, 2);
然后在textBox1_Validated中textBox_TextChanged事件里写
if (char.IsLetter(this.textBox1.Text.ToCharArray()[0]) != true)
this.errorProvider1.SetError(this.textBox1, "首字母必须为字母");
else if (this.textBox1.Text.Length < 5)
this.errorProvider1.SetError(this.textBox1, "必需至少有5个字符");
this.errorProvider1.ContainerControl = this;
this.errorProvider1.SetIconAlignment(this.textBox1, System.Windows.Forms.ErrorIconAlignment.MiddleRight);
this.errorProvider1.SetIconPadding(this.textBox1, 2);
然后在textBox1_Validated中textBox_TextChanged事件里写
if (char.IsLetter(this.textBox1.Text.ToCharArray()[0]) != true)
this.errorProvider1.SetError(this.textBox1, "首字母必须为字母");
else if (this.textBox1.Text.Length < 5)
this.errorProvider1.SetError(this.textBox1, "必需至少有5个字符");