Windows 窗体 - Tab 键在子面板中不起作用 [英] Windows Form - Tab key does not work in a child panel

查看:21
本文介绍了Windows 窗体 - Tab 键在子面板中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一些文本框和按钮的表单子面板.我尝试为这些控件设置 tabstop 和 tabindex 属性,以便用户可以从一个控件切换到下一个控件.但是由于某种原因,tabbing 不起作用,curor 停留在我按下 tab 键时具有焦点的同一个字段上.我在 .Net 3.5 框架中使用 C#.下面是我的代码的样子 -

I have a child panel in a form which contains some text boxes and buttons. I tried setting tabstop and tabindex properties for these controls so that the user can tab from one control to the next. But for some reason the tabbing does not work, the curor stays on the same field which has the focus when I press the tab key. I am using C# with .Net 3.5 framework. Below is how my code looks like -

  rightPanel.Controls.Clear();
        marketMessageLabel = new Label();
        marketMessageLabel.Location = new Point(0, 20);            
        marketMessageLabel.AutoSize = false;
        marketMessageLabel.Size = new Size(rightPanel.Width, 42);
        marketMessageLabel.BackColor = Color.White;            
        marketMessageLabel.Font = new System.Drawing.Font("Verdana", 8.00F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        rightPanel.Controls.Add(marketMessageLabel);                        

        signinUserNameLabel = new Label();
        signinUserNameLabel.Location = new Point(0, 150);
        signinUserNameLabel.Size = new Size(60, 14);
        signinUserNameLabel.BackColor = Color.White;
        signinUserNameLabel.Text = "User Name";            
        signinUserNameLabel.Font = new System.Drawing.Font("Verdana", 9.00F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        rightPanel.Controls.Add(signinUserNameLabel);

        signinUserNameTextBox = new TextBox();
        signinUserNameTextBox.Location = new Point(0, 170);
        signinUserNameTextBox.Width = this.Width - 80;
        signinUserNameTextBox.Font = new System.Drawing.Font("Verdana", 9.00F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));         
        signinUserNameTextBox.TabIndex = 0;
        signinUserNameTextBox.TabStop = true;

        rightPanel.Controls.Add(signinUserNameTextBox);

        signinPasswordLabel = new Label();
        signinPasswordLabel.Location = new Point(0, 192);
        signinPasswordLabel.Size = new Size(100, 14);
        signinPasswordLabel.Font = new System.Drawing.Font("Verdana", 9.00F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        signinPasswordLabel.BackColor = Color.White;
        signinPasswordLabel.Text = "Password";            
        rightPanel.Controls.Add(signinPasswordLabel);                      

        signinPasswordTextBox = new TextBox();
        signinPasswordTextBox.Location = new Point(0, 210);
        signinPasswordTextBox.Width = this.Width - 80;            
        signinPasswordTextBox.PasswordChar = '*';
        signinPasswordTextBox.TabIndex = 1;
        signinPasswordTextBox.TabStop = true;
        rightPanel.Controls.Add(signinPasswordTextBox);

        signInButton = new Button();
        signInButton.Text = "Sign In";
        signInButton.Font = new System.Drawing.Font("Verdana", 9.00F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        signInButton.Width = 70;            
        signInButton.BackColor = Color.White;
        signInButton.Location = new Point(0,240);
        signInButton.Click += new EventHandler(signInButton_Click);
        signInButton.TabIndex = 2;
        signInButton.TabStop = true;
        rightPanel.Controls.Add(signInButton);

推荐答案

另一个可能的问题是,如果制表符"不起作用的表单位于非模态显示的表单上.

Another possible problem is if the form where the "tabbing" does not work is on a form that is not displayed modally.

由于某些原因,如果使用 .show 显示子表单,tabbing"有时不起作用,而您更愿意使用 .ShowDialog 显示表单.

For some reasons, "tabbing" sometimes does not work if a child form is displayed with .show, and you'd rather display the form with .ShowDialog.

这篇关于Windows 窗体 - Tab 键在子面板中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆