flowlayoutpanel and horizontal scrollbar issue

26,472

Solution 1

If you dock the flowlayoutpanel on the top, it take the size of the parent control. So if you want a horizontal scroll, you need to set the AutoScrollMinSize of the form (or usercontrol).

Otherwise, you can do this :

this.AutoScroll = true;    
this.fLayoutPnl.Dock = System.Windows.Forms.DockStyle.None;
this.fLayoutPnl.AutoSize = true;
this.fLayoutPnl.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.fLayoutPnl.Location = new System.Drawing.Point(0, 10);
this.fLayoutPnl.Name = "fLayoutPnl";
this.fLayoutPnl.Size = new System.Drawing.Size(1245, 30);

Solution 2

fLayoutPnl.WrapContents = false;

This would solve the issue. If a scroll bar is needed, set the MinimumSize property of the panel, after which the scroll bar should appear

Solution 3

To view all the contents of flow layout panel by scrolling vertically, set AutoScroll property to True and don't forget to set WrapContents property to True. If the contents are to be viewed by scrolling horizontally, set AutoScroll property to True and don't forget to set WrapContents property to False.

Share:
26,472
Calvin
Author by

Calvin

a junior developer who wants to gain more experience and become a better developer.

Updated on August 05, 2022

Comments

  • Calvin
    Calvin almost 2 years

    I am using a flowlayoutpanel which have a lot of buttons per logic sake. I'm having an issue of when I resize the window, I'm not I'm not able to see all the buttons lined up horizontally when the window gets smaller. Instead as the window gets smaller, the buttons drops down to the next line. Can anyone help me on how to resolve this issue? I just want the buttons to line up horizontally, when the window gets smaller, have a horizontal scrollbar. Below is what I have.

    fLayoutPnl.Controls.Add(btn1);
    // snipped adding buttons from 2 to 15
    fLayoutPnl.Controls.Add(btn16);
    fLayoutPnl.Dock = System.Windows.Forms.DockStyle.Top;
    fLayoutPnl.Location = new System.Drawing.Point(0, 10);
    fLayoutPnl.Name = "fLayoutPnl";
    fLayoutPnl.Size = new System.Drawing.Size(1245, 30);