简体   繁体   English

如何在 FlowLayoutPanel 中禁用水平滚动条?

[英]How to disable horizontal scroll bar in FlowLayoutPanel?

I have a FlowLayoutPanel and there are multiple controls on it.我有一个 FlowLayoutPanel,上面有多个控件。 I only want to scroll in vertical direction.我只想在垂直方向滚动。 But when I set AutoScroll = true , I got both Vertical and Horizontal Scroll bars.但是当我设置AutoScroll = true ,我得到了垂直和水平滚动条。 How could I disable the horizontal scroll bar and only keep the vertical scroll bar working?如何禁用水平滚动条而只保持垂直滚动条正常工作?

  • Set AutoScroll to true自动滚动设置为 true
  • Set WrapContents to false.WrapContents设置为 false。
  • Make sure the size is wider than the controls' width plus the width of a vertical scrollbar.确保尺寸大于控件的宽度加上垂直滚动条的宽度。

The horizontal scrollbar should disappear.水平滚动条应该消失。 If it doesn't, please provide some more information.如果没有,请提供更多信息。

Set AutoScroll to true.将 AutoScroll 设置为 true。 Set WrapContents to false.将 WrapContents 设置为 false。 Set Padding Right to 10.将 Padding Right 设置为 10。

It's work pretty fine for me.这对我来说很好用。

Here is how I implement to have multiple labels on a FlowLayoutPanel with wrap text(WrapContents = true), verticalscrollbar only.这是我如何实现在 FlowLayoutPanel 上有多个标签,并带有换行文本(WrapContents = true),仅限垂直滚动条。

  1. I have a flowLayoutPanel1 on a form我在表单上有一个 flowLayoutPanel1
  2. Set properties of form and flowLayoutPanel1 like below:如下设置 form 和 flowLayoutPanel1 的属性:

form:形式:

AutoScroll = True
FormBorderStyle = Sizable(default)

flowLayoutPanel1: flowLayoutPanel1:

Anchor = Top, Left, Right
AutoSize = True
FlowDirection = TopDown
WrapContents = true
  1. Implement this code on form class for testing在表单类上实现此代码以进行测试

 int coorY = 0; public Form2() { InitializeComponent(); for (int i = 0; i < 100; i++) { flowLayoutPanel1.Controls.Add(new Label { Location = new Point(0, coorY + 20), Font = new Font("Segoe UI", 10f), Text = "I have a FlowLayoutPanel and there are multiple controls on it. I only want to scroll in vertical", Width = flowLayoutPanel1.Width, AutoSize = true }); coorY += 20; } }

Vertical scrollbar in action垂直滚动条在起作用

        flowLayoutPanel1.AutoScroll = false;
        flowLayoutPanel1.HorizontalScroll.Maximum = 0;
        flowLayoutPanel1.VerticalScroll.Maximum = 0;
        flowLayoutPanel1.AutoScroll = true;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM