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);
In the FlowLayoutPanel are several equal-sized elements. Flow Direction is TopDown. Default is WrapContens to false, all elements are displayed below each other, and when the panel size is too small, I get a vertical scrollbar. If the width of the FlowLayoutPanel is changed and >= 2 * element width, set WrapContents=true.
Then, go to the Toolbox and select the FlowLayoutPanel control then drag it inside your Form; you can make it leave some space for the Bunifu Vertical ScrollBar to fit right beside it: Now add some controls (or one control multiple times) inside the FlowLayoutPanel until some of the controls disappear or cannot be seen.
It’s actually possible to hide the Scroll Bars and replace them with Bunifu’s Scroll Bars, both the horizontal and the vertical scrolls. Here’s a short and quick tutorial on this:
similar functionality is there (with the name of LinearLayout) as provided by FlowLayoutPanel and has a unique property called alignment. The Alignment when set to Middle automatically locates controls in middle. Are you aware of such functionality in FlowLayoutPanel as well ?
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);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With