【发布时间】:2013-07-02 20:19:15
【问题描述】:
我正在尝试实现嵌套 TableLayoutPanel。我尝试在父 TableLayoutPanel 中动态创建/加载子 TableLayoutPanel。 为此,我采用父 TableLayoutPanel 并从 Visual Studio 工具箱中绘制它。 one DropDownList for dynamically to create child TableLayoutPanel I assign some values to dropdownlist such as 2*2,2*3,3*3,4*4 when the selected index change is fire is draws the child TableLayoutPanel. 我的代码在下面
private void cmbRowsColumns_SelectedIndexChanged(object sender, EventArgs e)
{
var selectedPair = new KeyValuePair<string, string>();
selectedPair = (KeyValuePair<string, string>)cmbRowsColumns.SelectedItem;
string[] rowcolumn = selectedPair.Value.Split('*');
string strRowCount = rowcolumn[0];
int rowCount = Convert.ToInt32(strRowCount);
string strColumnCount = rowcolumn[1];
int columnCount = Convert.ToInt32(strColumnCount);
DynamicallyGenerateColumn(rowCount, columnCount);
}
private void DynamicallyGenerateColumn(int rowCount, int columnCount)
{
parentTableLayoutPanel.Controls.Clear();
parentTableLayoutPanel.ColumnStyles.Clear();
parentTableLayoutPanel.RowStyles.Clear();
parentTableLayoutPanel.ColumnCount = columnCount;
parentTableLayoutPanel.RowCount = rowCount;
for (int i = 0; i < columnCount; i++)
{
parentTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
for (int j = 0; j < rowCount; j++)
{
if (i == 0)
{
parentTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
}
TableLayoutPanel objTableLayoutPanel = new TableLayoutPanel();
parentTableLayoutPanel.Controls.Add(objTableLayoutPanel, i, j);
}
}
}
但实际上问题是当我创建子 TableLayoutPanel 格式不正确
【问题讨论】:
-
什么不合适?您看不到任何子面板或它们的编号有误?
-
@Bolu 我想在父 TableLayoutPanel 中显示子 TableLayoutPanel 格式正确。
-
你现在用上面的代码得到了什么结果?
-
这种问题需要截图来描述一下。
-
@KingKing 我添加了屏幕截图以获得更清晰的想法
标签: c# winforms tablelayoutpanel