开发者

How to disable horizontal scroll bar in FlowLayoutPanel?

I have a 开发者_开发百科FlowLayoutPanel and there are multiple controls on it. I only want to scroll in vertical direction. But when I set AutoScroll = true, I got both Vertical and Horizontal Scroll bars. How could I disable the horizontal scroll bar and only keep the vertical scroll bar working?


  • Set AutoScroll to true
  • Set WrapContents to 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. Set WrapContents to false. Set Padding Right to 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.

  1. I have a flowLayoutPanel1 on a form
  2. Set properties of form and flowLayoutPanel1 like below:

form:

AutoScroll = True
FormBorderStyle = Sizable(default)

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜