c#windows窗体Tab顺序

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

c# windows form Tab Order

c#winformstab-ordering

提问by Sertan Pekel

I have a windows form in C# project that keeps Student Info. I caught the image: enter image description here

我在 C# 项目中有一个 Windows 窗体,用于保存学生信息。我抓到了图像: 在此处输入图片说明

I want to add data with sequential order as follows but when I enter data to Surname textbox, TAB button jumps to E-Mail textbox, then Phone Number textbox and lastly to Date of Birth DateTimePicker.

我想按如下顺序添加数据,但是当我将数据输入到姓氏文本框时,TAB 按钮跳转到电子邮件文本框,然后是电话号码文本框,最后是出生日期 DateTimePicker。

I made all control's TabStop property "False" on the form except these textboxes. And I arranged their TabOrder via Properties Section as follows 0,1,2.. as I intented. But the order followed as I wrote above. Then I opened Tab Order function via "View" on menu strip.. I clicked all controls which I wanted to use in order, but no use. The form and Tab button act as before. I caught Tab Order function image below:

除了这些文本框,我在表单上设置了所有控件的 TabStop 属性“False”。我按照我的意图通过属性部分将它们的 TabOrder 安排为如下 0,1,2..。但是按照我上面写的顺序。然后我通过菜单条上的“查看”打开了标签顺序功能..我点击了我想按顺序使用的所有控件,但没有用。表单和 Tab 按钮的作用和以前一样。我在下面找到了 Tab Order 函数图像:

enter image description here

在此处输入图片说明

What shall I do now?

我现在该怎么办?

采纳答案by Trevor Elliott

TabIndex is important for controls which are siblings of the same parent. However, if your TextBox and ComboBox controls are each inside different parents then their parent controls must have a the proper TabIndex.

TabIndex 对于属于同一父级的同级控件很重要。但是,如果您的 TextBox 和 ComboBox 控件分别位于不同的父控件中,则它们的父控件必须具有正确的 TabIndex。

In the Windows Forms Designer you can see which controls are children of which panels by bringing up the Document Outline. Go to View -> Other Windows -> Document Outline.

在 Windows 窗体设计器中,您可以通过调出文档大纲来查看哪些控件是哪些面板的子项。转到查看 -> 其他窗口 -> 文档大纲。

If each TextBox or ComboBox is directly inside a parent then its TabIndex doesn't matter, it can be 0. It's the parent (and possibly the parent's parent's) TabIndex which needs to be in order.

如果每个 TextBox 或 ComboBox 直接位于父级内部,则其 TabIndex 无关紧要,它可以为 0。它是父级(也可能是父级的父级)TabIndex 需要按顺序排列。