当尝试使用方法在flowLayoutPanel1中添加UserControl时
获取比所需数量更多的控件
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
发布于 2018-09-20 23:54:49
删除了(C_Rows + 1),将条件更改为C_rows = 1,以便您的.ToString将输出1-4。它现在应该输出所有进入的内容。
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);https://stackoverflow.com/questions/52428729
复制相似问题