如果只是在textBox的enter事件中用 txt.SelectAll()
或 txt.SelectionStart = 0; //设置起始位置
txt.SelectionLength = txt.TextLength; //设置长度
则不管用。
解决方案:
step1: 它的enter事件中
private void txtStart_Enter(object sender, EventArgs e)
{
TextBox txt = sender as TextBox;
txt.SelectAll();
}
step2: 它的mouseClick事件中
private void txtStart_MouseClick(object sender, MouseEventArgs e)
{
TextBox txt = sender as TextBox;
txt.Tag = 1;
txt.SelectAll();
}
step 3: 它的leave事件中
private void txtEnd_Leave(object sender, EventArgs e)
{
TextBox txt = sender as TextBox;
txt.Tag = 0;
}