动态地向表格布局面板添加行 [英] Dynamically add row to Table Layout Panel

查看:109
本文介绍了动态地向表格布局面板添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图动态地将行添加到表格布局面板,我在这里的代码添加了行,但间距是关闭的。当它添加行时,它比之前的行小。关于如何添加一行格式与之前相同的任何想法?
谢谢。 

I am trying to add rows dynamically to a Table Layout Panel, and the code I have here adds the row, but the spacing is off. When it adds the row it is smaller than the row before. Any ideas on how to add a row that is also formatted the same as the previous? Thanks. 

 int A = 1;
        public TextBox AddNewTextBox()
        {
            TextBox txt = new TextBox();
            this.Controls.Add(txt);
            txt.Top = A * 28;
            txt.Left = 15;
            txt.Text = " ";
            A = A + 1;
            return txt;

        }
        public void DeleteTextBox()
        {
            if (A >= 2)
            {
                tableLayoutPanel1.Controls.RemoveAt(A);
                A--;
            }
        }
        private void AddRowBTN_Click(object sender, EventArgs e)
        {
            this.tableLayoutPanel1.RowCount++;

            this.tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 28.57143F));
            tableLayoutPanel1.Controls.Add(AddNewTextBox());
            if(A >= 10)
            {
                this.tableLayoutPanel1.Size = new Size((282),(207*2)) ;
            }
        }
        private void button8_Click(object sender, EventArgs e)
        { 
            DeleteTextBox();
        }





            txt.Left = 15;

            txt.Text =" " ;;

            A = A + 1;

            return txt;



        }¥b $ b        public void DeleteTextBox()

        {

            if(A> = 2)

            {

                tableLayoutPanel1.Controls.RemoveAt(A);

                A--;

            }¥b $ b        }¥b $ b        private void AddRowBTN_Click(object sender,EventArgs e)

        {

            this.tableLayoutPanel1.RowCount ++;
$


            this.tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent,28.57143F));

            tableLayoutPanel1.Controls.Add(AddNewTextBox());

            if(A> = 10)

            {

                this.tableLayoutPanel1.Size = new Size((282),(207 * 2));

            }¥b $ b        }¥b $ b        private void button8_Click(object sender,EventArgs e)

        { 

            DeleteTextBox();

        }



            txt.Left = 15;
            txt.Text = " ";
            A = A + 1;
            return txt;

        }
        public void DeleteTextBox()
        {
            if (A >= 2)
            {
                tableLayoutPanel1.Controls.RemoveAt(A);
                A--;
            }
        }
        private void AddRowBTN_Click(object sender, EventArgs e)
        {
            this.tableLayoutPanel1.RowCount++;

            this.tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 28.57143F));
            tableLayoutPanel1.Controls.Add(AddNewTextBox());
            if(A >= 10)
            {
                this.tableLayoutPanel1.Size = new Size((282),(207*2)) ;
            }
        }
        private void button8_Click(object sender, EventArgs e)
        { 
            DeleteTextBox();
        }

推荐答案

嗨landino11,

Hi landino11,

感谢您发布此处。



>>当它添加行时,它小于之前的行。 



请尝试以下代码: 

$
1.编辑行: 显示:行( AutoSize)并删除第二行

Thank you for posting here.

>>When it adds the row it is smaller than the row before. 

Please try the code as follows: 

1.Edit rows : Show:Rows(AutoSize) And Delete the second row

2.这是完整的代码:

2.Here is the complete code:

private void AddRowBTN_Click(object sender, EventArgs e)
        {
            tableLayoutPanel1.AutoScroll = true;

            this.tableLayoutPanel1.RowCount++;

            tableLayoutPanel1.Controls.Add(AddNewTextBox());
        }

问候,

Regards,

建国


这篇关于动态地向表格布局面板添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆