如何更改列的顺序TableLayoutPanel c#

时间:2013-03-29 10:45:31

标签: c# .net winforms visual-studio tablelayoutpanel

我有一个TableLayoutPanel控件,其中有一行包含x列。内部的每个单元都有一个Panel控件 我想在运行时用列y交换列x。

我该怎么做?

问题再次出现:如何更改tablelayoutPanel中的列顺序?

1 个答案:

答案 0 :(得分:2)

如果您有对每个Panel控件的引用,请使用它们并跳过下面代码的前两行(即我在下面使用的GetControlFromPosition()函数来获取对控件的引用) -

Control ctr1 = tableLayoutPanel1.GetControlFromPosition(0, 0);
Control ctr2 = tableLayoutPanel1.GetControlFromPosition(1, 1);

tableLayoutPanel1.SetCellPosition(ctr1, new TableLayoutPanelCellPosition(1, 1));
tableLayoutPanel1.SetCellPosition(ctr2, new TableLayoutPanelCellPosition(0, 0));

将0和1替换为要放置控件的行和列索引..

相关问题