flowlayoutpanel和水平滚动条问题 [英] flowlayoutpanel and horizontal scrollbar issue

查看:469
本文介绍了flowlayoutpanel和水平滚动条问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个flowlayoutpanel,每个逻辑上都有很多按钮.我在调整窗口大小时遇到​​问题,不是在窗口变小时看不到所有按钮水平排列.取而代之的是,随着窗口变小,按钮会下降到下一行.谁能帮助我解决这个问题?我只希望按钮水平排列,当窗口变小时,有一个水平滚动条.以下是我所拥有的.

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);

推荐答案

如果将flowlayoutpanel停靠在顶部,则会占用父控件的大小. 因此,如果要水平滚动,则需要设置表单(或用户控件)的AutoScrollMinSize.

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).

否则,您可以这样做:

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);

这篇关于flowlayoutpanel和水平滚动条问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆