8

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

有一个包含几个复选框的组框“标志”。“标志”在“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.
4

2 回答 2

13

对于System.Windows.Forms.GroupBox

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

来自MSDN - 如何:在 Windows 窗体上设置 Tab 键顺序

此外,默认情况下,GroupBox 控件有自己的 TabIndex 值,它是一个整数。GroupBox 控件本身不能在运行时获得焦点。因此,GroupBox 中的每个控件都有自己的十进制 TabIndex 值,从 .0 开始。自然,随着 GroupBox 控件的 TabIndex 增加,其中的控件也会相应增加。如果将 TabIndex 值从 5 更改为 6,则其组中第一个控件的 TabIndex 值将自动更改为 6.0,依此类推

此外,请确保GroupBox的TabStopflag属性未设置为 false。我相信 false 是默认值。

对于System.Windows.Controls GroupBox

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

更新:您的所有控件似乎都被添加到groupBox3. 您应该确保它们中的每一个都仅添加到其包含的组框中。例如,checkBox1,checkBox2checkBox3都应该被添加到flag,它本身应该被添加到groupBox1groupBox3应该只包含 Back、Next、Finish 和 Cancel。

于 2012-06-15T14:17:08.053 回答
2

我发现在 WinForms 组框中获取选项卡顺序的唯一方法是在生成的 InitializeControl 方法中更改控件添加到组框中的顺序。

如果您有多个分组框,则必须检查将分组框添加到其容器中的顺序并可能更改它。

我真的不喜欢编辑生成的代码,但据我所知,这是解决此问题的唯一方法。

设置组框的 TabStop 属性根本没有帮助。

于 2014-06-15T08:18:38.623 回答