flowlayoutpanel and horizontal scrollbar issue
Asked Answered
M

3

8

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);
Mesics answered 2/7, 2012 at 19:11 Comment(1)
That's what the "flow" in FlowLayoutPanel means.Signorelli
F
17

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);
Frugal answered 2/7, 2012 at 19:37 Comment(5)
I understand that but if I dont use the flowlayoutpanel, all my buttons will be created horizontally which isnt what I want. I want them to flow vertically with the exception of if I hide a button, it wont leave any gap inbetween them.Mesics
Ok, I edited my response with an example. In this exemple, the buttons are on a line. This is what you want?Frugal
thanks for the help, I was able to implement this and got the horizontal scroll bar. Now, another issue arises. The verticle scrollbar now appears too. I dont want to show the verticle scrollbar. I've tried, this.fLayoutPnl.VerticalScroll.Visible = false but no avail. I've also tried adding this code to the constructor but again, doesnt help. Do you have any suggestion?Mesics
The vertical scrollbar is on your FlowLayoutPanel or on your form?Frugal
Ok, so if I understand everything. You want the flowlayout panel on a line, with horizontal scrollbar on the form. But your problem is your flowlayoutpanel have a vertical scrollbar. Are you sure AutoScroll of the flowlayoutpanel is set to false? Set AutoScroll = true only on your formFrugal
C
13
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

Cazzie answered 20/1, 2016 at 4:5 Comment(0)
F
5

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.

Farrell answered 8/1, 2019 at 3:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.