Multi-Row Autosize Scrollable FlowLayoutPanel

我是研究僧i 提交于 2019-11-28 14:06:41

To get the result like you see in screenshot:

  • Put your FlowLayoutPanel in a Panel with AutoScroll property set to true
  • Set AutoSize property of your FlowLayoutPanel to true
  • Set WrapContent property of your FlowLayoutPanel to true (Default)
  • Set AutoScroll property of your FlowLayoutPanel to false (Default)
  • When adding controls you can use SetFlowBreak to break the flow of controls for those one you need.

Screenshot

Code

private void button1_Click(object sender, EventArgs e)
{
    for (int i = 0; i < 20; i++)
    {
        var btn = new Button() { Text = i.ToString() };
        if (i == 5 || i==15 )
            this.flowLayoutPanel1.SetFlowBreak(btn, true);
        this.flowLayoutPanel1.Controls.Add(btn);
    }
}

Here I am breaking the flow, at 5 and 15.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!