简体   繁体   English

TableLayoutPanel:如何通过动态添加的控件使用 Tab 键导航?

[英]TableLayoutPanel: How can i navigate with tab key through dynamically added controls?

I have a form which contains a dynamically added TableLayoutPanel, which contains some dynamically added Labels, TextBox, CheckBox.我有一个包含动态添加的 TableLayoutPanel 的表单,其中包含一些动态添加的标签、文本框、复选框。 I am obtaining exactly the visualization I would like to have, but I am struggling to get the "tab key" to work for moving from one control to the other.我正在获得我想要的可视化效果,但我正在努力使“tab 键”能够从一个控件移动到另一个控件。 I have tried to add a:我试图添加一个:

control.TabIndex = tabIndex++;
control.TabStop = true;

But this doesn't seem to have any impact...但这似乎没有任何影响......

This is the (tested) stub code:这是(经过测试的)存根代码:

class MyForm : Form
    {
    public MyForm()
        {
            InitializeComponent();

            string[] titles = {"first","second"};
            var myLayout = new TableLayoutPanel();
            myLayout.AutoSize = true;
            int myTabIndex = 1; //Not really necessary
            int rowNumber = 0;

            foreach (var title in titles)
            {
                var label = new Label();
                label.Text = title;
                myLayout.Controls.Add(label, 0, rowNumber);
                var control = new TextBox();
                control.TabIndex = myTabIndex++; //Not really necessary
                myLayout.Controls.Add(control, 1, rowNumber);
                rowNumber++;
            }
            this.Controls.Add(myLayout);
        }
    }

This is the window I get, and I am not able to navigate from first to second field using the tab key.这是我得到的窗口,我无法使用 Tab 键从第一个字段导航到第二个字段。

简单的 TableLayourPanel 表单


Update:更新:
Applying Visual Studio 2013 Update 5 did not help.应用Visual Studio 2013 Update 5没有帮助。

Something must have been corrupted in my project.我的项目中一定有什么东西被破坏了。 The best I could do is to move on with a new clean Windows Form project, and everything now is working.我能做的最好的事情就是继续一个新的干净的 Windows 窗体项目,现在一切正常。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式设置动态创建的控件的列和行属性以嵌入TableLayoutPanel? - How can I programmatically set the Column and Row properties of controls that are dynamically created to embed within a TableLayoutPanel? 如何在动态创建的tablelayoutpanel上拖放控件 - How to drag and drop controls on dynamically created tablelayoutpanel 如何在 TableLayoutPanel 的特定单元格中放置多个控件 - How i can place multiple controls in a particullar cell of TableLayoutPanel 如何将控件移动到页面中动态添加的用户控件中? - How can I move controls into a dynamically added usercontrol into page? 添加控件时如何将控件随机化 - How can I randomize controls when they are added 如何处理来自用户选项卡中的控件的事件,该用户控件是从选项卡页派生的,该选项卡在运行时动态添加到选项卡控件? - How do I handle events from controls inside a User Control derived from a Tab Page meant to be added dynamically to a Tab Control at run time? 在运行时期间动态地向TableLayoutPanel添加控件 - Adding controls to TableLayoutPanel dynamically during runtime 如何处理动态创建的控件? - How can I dispose of dynamically created controls? 如何操作动态创建的控件? - How can I to manipulate dynamically created controls? Tab索引不适用于asp.net中的动态添加的控件 - Tab index is not working for dynamically added controls in asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM