textBox2.Focus();
textBox2.SelectionStart = 0;
textBox2.SelectionLength = textBox2.Text.Length;
这是找到的代码, 自己要用做函数,就写了一下
private void button2_Click(object sender, EventArgs e)
{
SelectAll(textBox2);
}
public static TextBox SelectAll(TextBox TB)
{
TB.Focus();
TB.SelectionStart = 0;
TB.SelectionLength = TB.Text.Length;
return TB;
}
本文介绍了一段C#代码,用于实现当点击按钮时,自动聚焦到指定的TextBox并全选其中的文本内容。该功能通过定义一个静态方法`SelectAll`来实现,可以方便地应用于各种需要全选文本的场景。
2105

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



