![](/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.