Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
540 views
in Technique[技术] by (71.8m points)

c# - Multi-Row Autosize Scrollable FlowLayoutPanel

I have 50 images. I need to add these images in FlowLayoutPanel, 30 images for 1st row after that wrap row and 20 images in second row. So I also need to show scrollbars on control.

I am dividing video into frames(images) and shown in FlowLayoutPanel. When I upload first video below are the code to set image :

for (i = 1; i < len - 1; i++)
{
    ImagePanel mybt = new ImagePanel(storagePath + words[0] + "_" + 
                                     i + ".jpg", words[0] + "_" + i + ".jpg");
    flowLayoutPanel1.Controls.Add(mybt);
}

After that when I upload second image I want to show images like in first row we have first video images after break I need to show second video upload images. If anybody knows how it can possible.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

enter image description here

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...