一般常常会设置高亮选中,供用户重新输入:
private void textBox1_MouseDown(object sender, MouseEventArgs e)
{
//No.1
string str = this.textBox1.Text;
if (!string.IsNullOrEmpty(str) && !string.IsNullOrEmpty(str.Trim()))
{
str = str.Trim();
this.textBox1.SelectionStart = 0; //设置选中的开始为止
this.textBox1.SelectionLength = this.textBox1.Text.Length; //设置选中文本长度
//No.2
//this.textBox1.Select(0,this.textBox1.Text.Length);
//this.textBox1.SelectAll();
this.textBox1.Focus();
}
}