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

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

运行环境:.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.

 

posted @ 2009-06-14 16:32  Zhongjian Zhang  阅读(2638)  评论(0编辑  收藏  举报