c# - TabIndex 无法正常工作

标签 c# .net winforms

我有一个 Windows 窗体应用程序。在表单上有三个组框。 每个组框都包含一些控件。请看图片。 form

有一个包含几个复选框的组框“标志”。 “flag”在“groupbox1”里面。 我使用 Tab 键遍历每个控件,但它不适用于“标志”中的复选框。我确实为每个控件设置了适当的 tabindex。

它适用于文本框和按钮,但适用于复选框。

为什么?感谢您的帮助。

编辑

 // groupBox2
        // 
        this.groupBox2.Controls.Add(this.pictureBox10);
        this.groupBox2.Controls.Add(this.pictureBox9);
        this.groupBox2.Controls.Add(this.pictureBox8);
        this.groupBox2.Controls.Add(this.pictureBox7);
        this.groupBox2.Controls.Add(this.chkStoplight);
        this.groupBox2.Controls.Add(this.lblStoplight);
        this.groupBox2.Controls.Add(this.chkIsCount);
        this.groupBox2.Controls.Add(this.chkExceptionFlag);
        this.groupBox2.Controls.Add(this.chkIsActive);
        this.groupBox2.Controls.Add(this.lblIsActive);
        this.groupBox2.Controls.Add(this.lblExceptionFlag);
        this.groupBox3.Controls.Add(this.lblIsCount);
        this.groupBox2.Location = new System.Drawing.Point(16, 201);
        this.groupBox2.Name = "groupBox2";
        this.groupBox2.Size = new System.Drawing.Size(321, 70);
        this.groupBox2.TabIndex = 10;
        this.groupBox2.TabStop = true;
        this.groupBox2.Text = "Flags";

        // 
        // chkStoplight
        // 
        this.chkStoplight.AutoSize = true;
        this.chkStoplight.Location = new System.Drawing.Point(44, 25);
        this.chkStoplight.Name = "chkStoplight";
        this.chkStoplight.Size = new System.Drawing.Size(15, 14);
        this.chkStoplight.TabIndex = 0;
        this.chkStoplight.UseVisualStyleBackColor = true;

        In the property, I found TabStop is true for chkStoplight.

最佳答案

对于System.Windows.Forms.GroupBox:

您应该确保您的 GroupBox flag具有适当的 TabIndex 集。

来自 MSDN - How to: Set the Tab Order on Windows Forms :

Additionally, by default, a GroupBox control has its own TabIndex value, which is a whole number. A GroupBox control itself cannot have focus at run time. Thus, each control within a GroupBox has its own decimal TabIndex value, beginning with .0. Naturally, as the TabIndex of a GroupBox control is incremented, the controls within it will be incremented accordingly. If you changed a TabIndex value from 5 to 6, the TabIndex value of the first control in its group automatically changes to 6.0, and so on

另外,确保 TabStop GroupBox 的属性 flag未设置为假。我相信 false 是默认设置。

对于System.Windows.Controls GroupBox:

确保 GroupBox.IsTabStop属性已设置。这也默认为 false。

<罢工> 更新:您的所有控件似乎都已添加到 groupBox3 .您应该确保它们中的每一个都只添加到其包含的组框中。例如,checkBox1 , checkBox2 , 和 checkBox3应全部添加到 flag ,它本身应该添加到 groupBox1 . groupBox3应该只包含 Back、Next、Finish 和 Cancel。

关于c# - TabIndex 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11052265/

相关文章:

c# - 使用 Unity 依赖注入(inject)注册 UrlHelper

c# - 当对象为空时 Linq to 对象 VS Linq to SQL

c# - 了解类 SmtpDeliveryMethod

c# - 如何更改 C# winforms 中未使用空间选项卡的背景颜色?

c# - 有没有办法在特定时间显示表单

c# - 如何以编程方式将 PictureBox 控件添加到选项卡页控件

c# - 当字符串中有反斜杠时,IndexOf 失败——为什么?

c# - 从 C# 代码生成包含触发器的 WPF 样式

c# - 动态、对象、变量

.net - 在用户目录中重定向log4net日志