private void button1_Click(object sender, EventArgs e)
{
textBox1.Focus();
textBox1.SelectionStart = 1; //设置起始位置
textBox1.SelectionLength = 2; //设置长度
textBox1.ScrollToCaret();
}
本文介绍了一个简单的C#应用程序实例,展示了如何通过按钮点击事件来设置TextBox中文字的选择范围,并使滚动条自动定位到选定的文字处。这对于需要用户交互操作的应用场景非常有用。
private void button1_Click(object sender, EventArgs e)
{
textBox1.Focus();
textBox1.SelectionStart = 1; //设置起始位置
textBox1.SelectionLength = 2; //设置长度
textBox1.ScrollToCaret();
}

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