如何从另一个表单获取 tableLayoutPanel 的行数?

How I can get the rowcount of a tableLayoutPanel from another form?

我有一个 form1 和一个按钮。此按钮创建了一个带有 TableLayoutPanel 的新表单(已为测试填充)。

是否可以获取RowCount并将其显示在第一个表单(form1)的按钮文本中?

如果在加载时初始化第二个窗体上的 TableLayoutPanel,那么您可以创建一个 property/method 即 returns 计数。在 form1 上,当您在单击按钮时加载 form2 时,代码可能如下所示。

Form2 frm2 = new Form2();
frm2.show();
int count = frm2.GetTableRowCount()
btn.Text  = count.ToString();

表格 2 上的 GetTableRowCount() 方法 returns table 行计数。