c# - 如何将复选框中的所有复选框添加到新表单?
问题描述
我想从中获取所有项目CheckedBoxList
并将其添加到一个新项目中,Form
因此对于每个已检查项目,我想要一个新Label
的,带有 checkItem 名称和TextBox
. 到目前为止,我正在这样做,但是当我打开表格时,我根本没有得到任何结果。我不知道如何获取检查的项目名称,我正在这样做:
labels[i].Text = i.ToString();
private void Button4_Click(object sender, EventArgs e)
{
testForm = new Test();
TableLayoutPanel tableLayoutPanel = new TableLayoutPanel() { AutoSize = true };
tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
int n = 0;
for (int i=0;i<checkedListBox1.CheckedIndices.Count;i++)
{
txtBox = new TextBox[checkedListBox1.CheckedIndices.Count];
labels = new Label[checkedListBox1.CheckedIndices.Count];
labels[i] = new Label();
labels[i].Text = i.ToString();
tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
tableLayoutPanel.SetCellPosition(labels[i], new TableLayoutPanelCellPosition(0, n++));
tableLayoutPanel.Controls.Add(labels[i]);
txtBox[i] = new TextBox();
tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
tableLayoutPanel.SetCellPosition(txtBox[i], new TableLayoutPanelCellPosition(0, n++));
tableLayoutPanel.Controls.Add(txtBox[i]);
}
Controls.Add(tableLayoutPanel);
testForm.ShowDialog();
}
有什么建议么?谢谢你投入的时间。
解决方案
解决方案是将代码更改为:
testForm.Controls.Add(tableLayoutPanel);
推荐阅读
- python - 如何扩大限制以包括 48 小时内的最长工作时间?
- python - 为什么我不能在函数内创建类对象?
- powershell - 将文件共享路径作为参数读取时出错
- javascript - 无法读取未定义的属性,并且此指向不在正确的位置
- python-3.x - 具有色阶和一种颜色的不需要值的颜色图
- python - 在 python 中实现 REP-tree 和 M5P-tree 算法
- ruby - Can't install gems using asdf
- python - Response payload is not completed using asyncio/aiohttp
- c - Why is it sometimes valid to write an include statement in a codeblock?
- ruby-on-rails - Rails Association Has_One Having Pluralisation Model Name Instead of Singular and not working