Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flowlayoutpanel and horizontal scrollbar issue

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);
like image 489
Calvin Avatar asked Jul 02 '12 19:07

Calvin


People also ask

How to get a vertical scrollbar in the flowlayoutpanel?

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.

How do I add the bunifu vertical scrollbar to my form?

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.

Is it possible to hide the scroll bars?

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:

Is it possible to align controls in Middle in flowlayoutpanel?

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 ?


2 Answers

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);
like image 103
Hyralex Avatar answered Oct 18 '22 00:10

Hyralex


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

like image 13
Teja Avatar answered Oct 18 '22 02:10

Teja