Use 1 ScrollBar for 2 FlowLayoutPanels

45 Views Asked by At

I have a TableLayoutPanel with 2 columns and 1 row. In each row is a FlowLayoutPanel in which I want to create Labels. It will have to much labels for my form and I want a scrollbar in it. I already got a scrollBar for each FlowLayoutPanel, but I would like to have

namespace Flow_layout_Panel_test1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
            flowLayoutPanel1.AutoScroll = true;
            flowLayoutPanel1.WrapContents = false;

            flowLayoutPanel2.FlowDirection = FlowDirection.TopDown;
            flowLayoutPanel2.AutoScroll = true;
            flowLayoutPanel2.WrapContents = false;
            //makes a scrollbar for each flowlayoutpanel

            for (int x = 0; x < 50; x++) //Example Labels
            {
                Label lbl1 = new Label();
                Label lbl2 = new Label();

                lbl1.Name = "lbl_" + x;
                lbl1.Text = x.ToString();

                lbl2.Name = "lbl2_" + x;
                lbl2.Text = x.ToString();

                flowLayoutPanel1.Controls.Add(lbl1);
                flowLayoutPanel2.Controls.Add(lbl2);
            }
        }
    }
}

How it currently looks: like

0

There are 0 best solutions below