C# 如何设置哪个控件获得应用程序启动的焦点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2063603/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 23:10:21  来源:igfitidea点击:

How to set which control gets the focus on application start

c#winformscontrolsfocusinit

提问by Dribbel

For a C# Windows Forms application, how do I set the default focus to a given control when my application starts?

对于 C# Windows 窗体应用程序,如何在我的应用程序启动时将默认焦点设置到给定控件?

采纳答案by Mehrdad Afshari

The one with the minimum tab index automatically gets the focus (assuming the TabStopproperty is set to true). Just set the tab indices appropriately.

标签索引最小的那个会自动获得焦点(假设该TabStop属性设置为 true)。只需适当设置选项卡索引。

By the way, Visual Studio provides a way to easily set tab indices by just clicking on the controls in the order you want. You can activate this feature by choosing "Tab Order" option in the "View" menu when you are in the form design view.

顺便说一下,Visual Studio 提供了一种只需按所需顺序单击控件即可轻松设置选项卡索引的方法。当您在表单设计视图中时,您可以通过在“视图”菜单中选择“选项卡顺序”选项来激活此功能。

You can also manually give the focus to a control by calling its Selectmethod when the form loads.

您还可以通过Select在窗体加载时调用其方法来手动将焦点赋予控件。