TabIndex的工作不正常不正常、工作、TabIndex

2023-09-03 05:15:17 作者:十夏九黎

我有一个Windows窗体应用程序。在窗体上有三个groupboxs。 每个组框包含了一些控制。请看到的图像。

有一个组框的标志,其中包含了一些checkboxs。 标记是在里面groupbox1。 我用Tab键来遍历每个控制,但它并不适用于checkboxs在标志的工作。我没有设置正确的tabIndex为每个控制。

它适用于textboxs和按钮,但checkboxs。

为什么呢?感谢您的帮助。

修改

  // 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 =新System.Drawing.Point(16,201);
        this.groupBox2.Name =groupBox2;
        this.groupBox2.Size =新System.Drawing.Size(321,70);
        this.groupBox2.TabIndex = 10;
        this.groupBox2.TabStop = TRUE;
        this.groupBox2.Text =标志;

        //
        // chkStoplight
        //
        this.chkStoplight.AutoSize =真;
        this.chkStoplight.Location =新System.Drawing.Point(44,25);
        this.chkStoplight.Name =chkStoplight;
        this.chkStoplight.Size =新System.Drawing.Size(15,14);
        this.chkStoplight.TabIndex = 0;
        this.chkStoplight.UseVisualStyleBackColor = TRUE;

        在属性中,我发现接受tab是真正的chkStoplight。
 

解决方案

对于 System.Windows.Forms.GroupBox

违法代缴社会保险费,导致员工不能正常享受工伤保险待遇

您应该确保您的分组框标志有一个合适的TabIndex集。

从 MSDN - 如何:设置Windows窗体的Tab键顺序:

  

此外,在默认情况下,一个GroupBox控件都有自己的TabIndex   值,这是一个整数。一个分组框控件本身不能有   重点在运行时。因此,一组框内的每个控制有其自己的   十进制tabIndex值,以0.0开始的。自然地,作为TabIndex的   的GroupBox控件递增,在它的控制将是   相应地增加。如果从5改变了tabIndex值6,   在组中的第一控制的tabIndex值自动   变化到6.0,等

此外,还要确保在TabStop您的分组框标记属性未设置为false。我相信假的是默认的。

对于 System.Windows.Controls的分组框

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

更新:看来,所有控件都被添加到 groupBox3 。您应该确保他们每个人都被只添加到它的含组框。例如, checkBox1 checkBox2 checkBox3 应全部加入标志,它本身应该加入 groupBox1 groupBox3 应该只包含上一步,下一步,完成和取消。

I have a windows form application. On the form there are three groupboxs. Each groupbox contains some controls. Please see the image.

There is a groupbox "flag" that contains a few checkboxs. "flag" is inside in "groupbox1". I used Tab key to go through each control but it doesn't work for checkboxs in "flag". I did set proper tabindex for each control.

It works for textboxs and buttons but checkboxs.

Why? Thanks for help.

EDIT

 // 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.

解决方案

For System.Windows.Forms.GroupBox:

You should make sure that your GroupBox flag has an appropriate TabIndex set.

From 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

Also, make sure the TabStop property of your GroupBox flag is not set to false. I believe false is the default.

For System.Windows.Controls GroupBox:

Make sure that the GroupBox.IsTabStop property is set. This also defaults to false.

Update: It appears that all of your controls are being added to groupBox3. You should make sure that each of them is being added only to its containing groupbox. For example, checkBox1, checkBox2, and checkBox3 should all be added to flag, which itself should be added to groupBox1. groupBox3 should only contain Back, Next, Finish, and Cancel.