首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么当我在flowLayoutPanel中添加了一定数量的控件时,在c #中添加的控件超过了所需的数量?

为什么当我在flowLayoutPanel中添加了一定数量的控件时,在c #中添加的控件超过了所需的数量?
EN

Stack Overflow用户
提问于 2018-09-20 23:38:52
回答 1查看 29关注 0票数 0

当尝试使用方法在flowLayoutPanel1中添加UserControl时

获取比所需数量更多的控件

代码语言:javascript
复制
public void count_rows_columns()
    {
        // delete All UserControls
        foreach (Control clear in flowLayoutPanel1.Controls.OfType<latest>())
        {
            flowLayoutPanel1.Controls.Remove(clear);
        }

        #region set latest bord


        decimal space_between_2columns =0;
        decimal count_rows = 0;
        decimal count_columns = 0;

         space_between_2columns = Convert.ToDecimal(((flowLayoutPanel1.Width - 1000) / 3));
         count_rows = ((flowLayoutPanel1.Height) / 145);
         count_columns = ((flowLayoutPanel1.Width) / 500);

        silk_section.Text = count_rows.ToString();



    if ((int)count_columns == 1)
        {
                                //count_rows here will be 4
            for (int C_rows = 0; C_rows < count_rows; C_rows++)
                {


                    latest latest1 = new latest();
                    latest1.Name = String.Concat("latest1_", (C_rows +1).ToString());
                    latest1.Left = ((flowLayoutPanel1.Width - latest1.Width) / 2);
                    latest1.Top = (latest1.Height * C_rows) + 32;

                    flowLayoutPanel1.Controls.Add(latest1);

                }

        }
}

当count_rows等于3时,我得到4;当count_rows等于4时,我得到7

但如果count_rows等于4,我想得到4

EN

回答 1

Stack Overflow用户

发布于 2018-09-20 23:54:49

删除了(C_Rows + 1),将条件更改为C_rows = 1,以便您的.ToString将输出1-4。它现在应该输出所有进入的内容。

代码语言:javascript
复制
for (int C_rows = 1; C_rows <= count_rows; C_rows++)
                {


                    latest latest1 = new latest();
                    latest1.Name = String.Concat("latest1_", (C_rows).ToString());
                    latest1.Left = ((flowLayoutPanel1.Width - latest1.Width) / 2);
                    latest1.Top = (latest1.Height * C_rows) + 32;

                    flowLayoutPanel1.Controls.Add(latest1);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52428729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档