簡體   English   中英

TableLayoutPanel:如何通過動態添加的控件使用 Tab 鍵導航?

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

我有一個包含動態添加的 TableLayoutPanel 的表單,其中包含一些動態添加的標簽、文本框、復選框。 我正在獲得我想要的可視化效果,但我正在努力使“tab 鍵”能夠從一個控件移動到另一個控件。 我試圖添加一個:

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

但這似乎沒有任何影響......

這是(經過測試的)存根代碼:

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);
        }
    }

這是我得到的窗口,我無法使用 Tab 鍵從第一個字段導航到第二個字段。

簡單的 TableLayourPanel 表單


更新:
應用Visual Studio 2013 Update 5沒有幫助。

我的項目中一定有什么東西被破壞了。 我能做的最好的事情就是繼續一個新的干凈的 Windows 窗體項目,現在一切正常。 在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM