您的位置:首页 > 其它

winform textBox光标进入时自动选中全部内容

2013-04-28 07:39 786 查看
如果只是在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;

                        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: