C# 如何禁用表单控件上的选项卡索引?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12271388/
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 do I disable a tab index on a control on a form?
提问by RJ.
I have a form with 2 buttons and 2 labels.
我有一个带有 2 个按钮和 2 个标签的表单。
I want to set button 1 = tabIndex = 0, button 2 = tabIndex = 1 and I do not want to set a tabIndex to the 2 labels, meaning that if the user presses tab, it'll go from button 1 to button 2.
我想设置 button 1 = tabIndex = 0, button 2 = tabIndex = 1 并且我不想将 tabIndex 设置为 2 个标签,这意味着如果用户按下 tab,它将从按钮 1 转到按钮 2。
How would I go about doing this?
我该怎么做呢?
采纳答案by itsme86
Just set the TabStop property of the Labels to false and the TabIndex property of the Buttons to whatever you want. You can do it right in the Properties window of the designer.
只需将标签的 TabStop 属性设置为 false 并将按钮的 TabIndex 属性设置为您想要的任何值。您可以直接在设计器的“属性”窗口中执行此操作。
回答by Beth
set the label's tabstop properties to false?
将标签的制表位属性设置为 false?
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.tabstop.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.tabstop.aspx
otherwise, just set the label's tabindex value to the value before the button. Then you can use accelerator keys to click on the button.
否则,只需将标签的 tabindex 值设置为按钮之前的值。然后您可以使用加速键单击该按钮。
回答by coolmine
回答by Willy David Jr
In my case, all my Labels don't have TabStop property.
就我而言,我所有的标签都没有TabStop property.
I cannot even set the TabIndex to -1either, since it will say Property value not valid.
我什至不能将 TabIndex 设置为-1两者之一,因为它会说Property value not valid.
But I notice that once I run the application, regardless on what value I have on my TabIndex for all my labels, it doesn't stop on any labels when I press my Tab on my keyboard.
但我注意到,一旦我运行该应用程序,无论我在 TabIndex 上为所有标签设置了什么值,当我按下键盘上的 Tab 键时,它都不会停在任何标签上。
The reason for this is that Label controls do not get focus. The only way to cause a Label control to gain focus is to call the Label.Focus method.
这样做的原因是 Label 控件没有获得焦点。使 Label 控件获得焦点的唯一方法是调用 Label.Focus 方法。
For more info, you can read this forum: MSDN Forum.
有关更多信息,您可以阅读此论坛:MSDN 论坛。
回答by Damith
As per the documentation on MSDN, The TabStop property is not relevant for the Labelclass, so setting TabStop to true has no effect. So i will set both label's tab indexes into 0 and button 1 will get tab index 1 and button 2 will get tab index 2
根据MSDN上的文档,TabStop 属性与 Label类无关,因此将 TabStop 设置为 true 无效。所以我将标签的标签索引设置为 0,按钮 1 将获得标签索引 1,按钮 2 将获得标签索引 2

