vb.net 选项卡索引不适用于面板中的控件?

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

Tab index does not work with controls in panels?

vb.netwinformspaneltabindex

提问by TypeM1smatch

I have a vb.net windows form with about 15 comboboxes and 15 textboxes, along with several other controls. All of these TextBoxesand ComboBoxesare located in panels. The reason for this is I need to adjust the visible property of controls based upon what the user selects/enters, so grouping each label and control together in their own panels seemed like an easy way to accomplish this.

我有一个 vb.net windows 窗体,其中包含大约 15 个组合框和 15 个文本框,以及其他几个控件。所有这些TextBoxes,并ComboBoxes都位于面板。这样做的原因是我需要根据用户选择/输入的内容来调整控件的可见属性,因此将每个标签和控件组合在它们自己的面板中似乎是实现此目的的简单方法。

I've set the tab order via properties, but it doesn't work. When I tab through my form, it skips around and does not follow the tab order that I've set. Is this because my controls are each located in separate panels? I've set TabStopto false for everything I don't want a tabstop on, I'm a little confused about what's going on here. It really seems that the fact that my ComboBoxesand TextBoxesare each inside their own panels is preventing my tab indices to work. Can anyone confirm this or have other ideas of what may be happening? TabIndexworks if I create a new form.

我已经通过属性设置了选项卡顺序,但它不起作用。当我浏览我的表单时,它会跳过并且不遵循我设置的 Tab 顺序。这是因为我的控件都位于不同的面板中吗?TabStop对于我不想要制表位的所有内容,我都设置为 false,我对这里发生的事情感到有些困惑。我ComboBoxesTextBoxes每个人都在自己的面板中这一事实似乎确实阻止了我的标签索引工作。任何人都可以确认这一点或对可能发生的事情有其他想法吗?TabIndex如果我创建一个新表单就可以工作。

回答by dizzy.stackoverflow

Believe it or not, the panel ordering absolutely DOES affect the TabIndex. I have found that the easiest way to deal with tab ordering on a multi-panel form is to use View>Tab Order as suggested by LarsTech. Then once the tab ordering is visible, you'll be able to see how the panels affect the overall ordering of the controls contained in each panel. Next, left-click one at a time on the actual panels, in the order that you want the flow to go. You'll notice that it will then automatically sub-order the controls inside each panel, with the overall panel ordering be in the order that you specified. Once this is done you can then click on each control inside each panel to set a control's relative tab order inside a given panel.

信不信由你,面板排序绝对会影响 TabIndex。我发现处理多面板表单上的 Tab 排序的最简单方法是使用 LarsTech 建议的 View>Tab Order。然后,一旦选项卡排序可见,您将能够看到面板如何影响每个面板中包含的控件的整体排序。接下来,在实际面板上一次左键单击一个,按照您希望流程进行的顺序。您会注意到它随后会自动对每个面板内的控件进行子排序,整个面板的排序将按照您指定的顺序进行。完成此操作后,您可以单击每个面板内的每个控件以在给定面板内设置控件的相对 Tab 键顺序。

回答by LarsTech

Try using "View - Tab Order" in the Visual Studio designer and click each container and control in the order you want. The tab index of the parent container (panels) matters.

尝试在 Visual Studio 设计器中使用“查看 - 选项卡顺序”,然后按所需顺序单击每个容器和控件。父容器(面板)的标签索引很重要。

回答by Zeddy

Setting TabStop to FALSE means it will skipped by when its turn comes in the Tab Order. Normally you would set TabStop for LABELs to FALSE and all other INTERACTIVE Controls to TABSTOP = True (unless the control is disabled off course).

将 TabStop 设置为 FALSE 意味着它会在轮到 Tab Order 时跳过。通常,您会将 LABEL 的 TabStop 设置为 FALSE,并将所有其他交互控件设置为 TABSTOP = True(除非该控件被禁用)。

Dont skip from Tab to Tab. Your TabStop and Tab Order ought to be something like the list below.

不要从 Tab 跳到 Tab。您的 TabStop 和 Tab Order 应该类似于下面的列表。

Name         Parent        TabOrder        TabStop
=======================================================
Form         -             0               -
TabStrip1    Form          1               True
Tab1         TabStrip1     2               True
Label1       Tab1          3               False
Textbox1     Tab1          4               True
Label2       Tab1          5               False
Combo1       Tab1          6               True

Tab2         TabStrip1     7               True
Label3       Tab2          8               False
Textbox2     Tab2          9               True
Label4       Tab2          10              False
Combo2       Tab2          11              True

Tab3         TabStrip1     12               True
Label5       Tab3          13               False
Textbox3     Tab3          14               True
Label6       Tab3          15               False
Combo3       Tab3          16               True

回答by Steve Shelton

I have found that you have to look at EVERY tab index for each control and grouping of controls (group box, panel, whatever). Unlike Classic VB, .Net doesn't update all the other tab indices for you. You can have as many controls as you want with the same tab index on a form, panel, or other grouping type.

我发现您必须查看每个控件和控件分组(组框、面板等)的每个选项卡索引。与 Classic VB 不同,.Net 不会为您更新所有其他选项卡索引。您可以根据需要在表单、面板或其他分组类型上使用相同的选项卡索引拥有任意数量的控件。

BTW, for those that posted the View - Tab Order menu item, thank you. I didn't know it was there and it helped me immensely to properly order a form I have with multiple nested group boxes. This was an excellent tool for reviewing the tab order. If you use this, be sure to pay attention to each level of nesting.

顺便说一句,对于那些发布“查看 - 选项卡顺序”菜单项的人,谢谢。我不知道它在那里,它极大地帮助了我正确订购具有多个嵌套组框的表单。这是查看 Tab 键顺序的绝佳工具。如果你使用这个,一定要注意每一级嵌套。