【发布时间】:2015-01-17 07:25:30
【问题描述】:
如何在 Windows 窗体中设置选项卡,其中要通过选项卡的文本框数量是动态的(取决于以前的用户输入)?
我现在在做什么
这可以很好地创建文本框,但我无法通过它们进行选项卡。
注意:numStates 是用户在之前的表单中输入的 int。
更新:我只隔离了这段代码并在 VS 2010 中对其进行了测试,并且选项卡可以正常工作,但在我的最终版本中却没有。 (见背景。)
BACKGROUND:用于 Enterprise Architect (EA) 的插件。我正在通过 .msi 安装程序部署加载项并在 EA 中测试最终安装,但选项卡不起作用。 我现在猜想在由 EA 插件创建的表单中与制表符有些不兼容??
System.Windows.Forms.TextBox[] textBoxes = new System.Windows.Forms.TextBox[numStates];
for (int index = 0; index < textBoxes.Length; index++)
{
textBoxes[index] = new System.Windows.Forms.TextBox();
textBoxes[index].Location = new System.Drawing.Point(126, yLocation);
textBoxes[index].Name = "stateName" + index;
textBoxes[index].Size = new System.Drawing.Size(161, 20);
textBoxes[index].TabStop = true;
textBoxes[index].TabIndex = index;
this.Controls.Add(textBoxes[index]);
textBoxes[0].Focus();
yLocation += 25;
}
我看过的内容
How to detect tab key pressing in C#?
- 以上两个问题的答案影响了我现在所做的事情。我是 尝试以编程方式设置跳位顺序。
Adding Event Handler for Dynamically Created to window Form
- 我认为我不能这样做,因为没有“_CheckedChanged” 文本框,我只想在它们按 Tab 时进行更改。
【问题讨论】:
-
如果你有动态数量的文本框 - 尝试使用
DataGridViewcontrol
标签: c# winforms visual-studio-2010 visual-studio enterprise-architect