![](/img/trans.png)
[英]How can I programmatically set the Column and Row properties of controls that are dynamically created to embed within a TableLayoutPanel?
[英]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 鍵從第一個字段導航到第二個字段。
更新:
應用Visual Studio 2013 Update 5沒有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.