如果只是在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;
}

本文提供了一种在TextBox控件中实现文本全选功能的方法。通过在TextBox的Enter事件、MouseClick事件及Leave事件中分别调用SelectAll()方法和其他辅助操作,确保用户能够方便地全选文本内容。
1万+

被折叠的 条评论
为什么被折叠?



