wpf 如何将光标焦点设置到文本框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22485650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set cursor focus to a TextBox?
提问by John Threepwood
How to set cursor focus to a TextBox?
如何将光标焦点设置到文本框?
I have a window pop up with a TextBoxand would like to focus the cursor to it. So a user can directly type text.
我有一个弹出的窗口,TextBox并希望将光标集中在它上面。所以用户可以直接输入文本。
I could not find a proper property. Is there one?
我找不到合适的财产。有吗?
回答by BRBT
To set focus on a textboxwhen your form loads you can do this:
要textbox在表单加载时将焦点设置在 a 上,您可以执行以下操作:
private void Form_Load(object sender, EventArgs e)
{
SomeTextBox.Select();
}
Note**You have to put it within the Form_Loadevent.
注意**你必须把它放在Form_Load事件中。

