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;
}
或 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;
}
相关文章推荐
- winform textbox光标进入时,自动切换到五笔输入法
- WinForm自动调整TextBox使其全部显示
- JavaScript实现进入某一页面时自动将鼠标光标放在某一textbox上
- winform textbox自动聚焦但不选中:
- word中怎么快速选中光标之前或之后的全部内容?
- 关于如何实现编辑框单击时自动选中全部内容的方法
- 在点击TextEditor编辑框后,默认是选中编辑框内的全部内容,去掉默认选择内容这个效果
- JavaScript 选择input光标所在位置 设置input的内容选中并得到选中的值
- winform窗口中实现按Enter键动态将光标定位到下一个textBox控件。以登录窗口为例
- jquery中focus()函数:当对象获得焦点后,自动把光标移到内容最后
- GridView中TextBox 有内容,选中当前行CheckBox
- 自动适应输入内容高度的TextBox控件 (转)
- winform模拟qq聊天界面的小功能textbox1输入自动跳到textbox2
- MFC Combobox 输入内容自动补全并选中缺失部分(类似qq登录输入账号)
- .Net C# WinForm -- 获取TextBox当前焦点所在位置,插入文本,选中文本
- ASP.NET 根据TextBox输入的内容自动定位到ListBox中项
- 基于jQuery的输入框在光标位置插入内容, 并选中
- 当鼠标滑过文本框自动选中输入框内容JS代码
- C# 保存所有TextBox,下次全部装入保存界面的输入框内容
- WINCE 扫描完自动下行和点击TEXTBOX高亮选中