【问题标题】:flowlayputpanel columns and rowsflowlayoutpanel 列和行
【发布时间】:2014-01-15 12:26:37
【问题描述】:

如何查找flowlayoutpanel排列的列数和行数。

FlowLayoutPanel panelstandard = new FlowLayoutPanel();
panelstandard.Size = new Size(1130,150);
panelstandard.Location = new Point(20, 250);
panelstandard.BorderStyle = BorderStyle.FixedSingle;
panelstandard.FlowDirection = FlowDirection.LeftToRight;

【问题讨论】:

  • Related 但不是很有帮助.. 你可以尝试枚举Controls 并获取它们的位置,如果Top 更改-> 新行开始(但有Margin,@987654326 @ 和 Padding 也要检查)。
  • 如果我将它用于复选框......那么我可以找到新行从哪个复选框开始。

标签: c# winforms


【解决方案1】:

你可以自己算:

int row = 0;
int column = -1;
int left = panelstandard.Controls[0].Left;
foreach(Control control in panelstandard.Controls)
{
    // as soon as wrap occurs
    if(control.Left < left)
    {
        // new row
        row++;
        column = 0;
    }
    else
        column++;
    left = control.Left + control.Width; // next control expected left

    // here you know [row; column] of the control
}

// here you know total rows and columns

这不关心控制Margin,如果你使用Dock和/或Anchor,这可能不起作用,但在一般情况下应该可以工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-29
    • 1970-01-01
    • 2016-06-25
    • 1970-01-01
    相关资源
    最近更新 更多