请教:TableLayoutPanel.Controls.Add中的下一个可行的单元位置(.net2.0,C#)

∥☆過路亽.° 提交于 2019-11-26 18:38:25

由于在新手区没有观众给意见,希望到精华区能找到帮助。谢谢。

运行环境:.net 2.0

AddAButtonIntoTable:

  private void button1_Click(object sender, EventArgs e)
        {
            Button b = new Button();
            b.Text = "new button" + (++index).ToString();
            tableLayoutPanel1.Controls.Add(b, (int)nColumn.Value, (int)nRow.Value);
        }
        int index = 0;

测试项目文件:/Files/zzj8704/TableLayoutTest.zip

初始状态:

问题:单击6次,出现如下结果,那位请解释为何结果如下.谢谢。

 

 

参考:

TableLayoutPanel1.Controls.Add(aButton,3,3);

Columns in a TableLayoutPanel are numbers starting at 1, while rows start at 0. Thus the
example shown above adds aButton to the cell in column 3 at row 3, which is actually the
fourth column and the fourth row the user sees. Note, however, that if a cell is already
occupied by a control, your control might not be added to that cell. Controls added to cells
at design time generally have precedence over controls added at run time. In these cases the
control is simply added to the next available cell. If you add the control to a cell that contains
another control that has been added at run time, the cell already in that position will usually
be moved down to the next available cell in favor of the control just added. As always, careful
testing is important.

 

转载于:https://www.cnblogs.com/zzj8704/archive/2009/06/14/1503103.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!