c# - flowlayoutpanel 和水平滚动条问题

标签 c# winforms flowlayoutpanel

我正在使用 flowlayoutpanel,出于逻辑考虑,它有很多按钮。当我调整窗口大小时,我遇到了一个问题,当窗口变小时,我无法看到所有水平排列的按钮。相反,随着窗口变小,按钮会下降到下一行。谁能帮我解决这个问题?我只想让按钮水平排列,当窗口变小时,有一个水平滚动条。以下是我所拥有的。

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。

否则,你可以这样做:

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

关于c# - flowlayoutpanel 和水平滚动条问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11299754/

相关文章:

c# - 如何将项目添加到窗口的上下文菜单中[仅适用于 pdf 文件和 doc 文件]

c# - 在 SSRS 2012 中由 C# 代码创建的报告返回 Client found response content type of '' ,但预期为 'text/xml'

c# - 根据Windows 8中的各种分辨率进行设计

c# - 如何在 WinForms 应用程序中取消 PLINQ 查询

winforms - 用户界面建议 : how to design a form with a lot of data

java - 如何调整Java Swing布局中的组件?

c# - .NET MVC 3 如何循环模型状态错误并强制 ModelState.Valid 或禁用特定错误?

C# 图片框的加载时间

c# - 如何在 flowlayout 面板中滚动而不在 Windows 窗体中显示滚动条

c# - C# winform 中的滚动容器