textBox文本选中

williams_cn 2009-02-25 03:18:25
我的TextBox里面预设了文本,我想问一下

怎么在我启动窗体的时候,设置焦点在我的TextBox中

同时,光标在我的textBox预设文本的最右边,而不是选中所有文体????
...全文
67 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Galllop 2009-02-25
  • 打赏
  • 举报
回复
public Form1()
{
InitializeComponent();

textBox2.Text = "Auto Select Text Demo";
textBox2.Tag = false;
textBox2.GotFocus += new EventHandler(textBox2_GotFocus);
textBox2.MouseUp += new MouseEventHandler(textBox2_MouseUp);
}

void textBox2_MouseUp(object sender, MouseEventArgs e)
{
//如果鼠标左键操作并且标记存在,则执行全选
if (e.Button == MouseButtons.Left && (bool)textBox2.Tag == true)
{
textBox2.SelectAll();
}

//取消全选标记
textBox2.Tag = false;
}

void textBox2_GotFocus(object sender, EventArgs e)
{
textBox2.Tag = true; //设置标记
textBox2.SelectAll(); //注意1
}
Galllop 2009-02-25
  • 打赏
  • 举报
回复
mark
jwdream2008 2009-02-25
  • 打赏
  • 举报
回复
1.
将该控件的tabindex设置为该画面上所有控件tabindex值中最小的一个,比如:0.
2. TextBox.SelectionStart=TextBox.Text.Length;
tmd456 2009-02-25
  • 打赏
  • 举报
回复
1、 TextBox.Focus();
2、 TextBox.SelectionStart=TextBox.Text.Length;
zgke 2009-02-25
  • 打赏
  • 举报
回复
textBox1.Select(textBox1.Text.Length, 0);

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧