我有一个FlowLayoutPanel,上面有多个控件。我只想垂直方向滚动,但是当我设置AutoScroll = true
时,我得到了水平和垂直滚动条。如何禁用水平滚动条并保留仅垂直滚动条的功能?
HorizontalScroll.Maximum = 0;
来禁用水平滚动条,并确保VerticalScroll.Visible = true;
以保留垂直滚动条的功能。我有一个FlowLayoutPanel,上面有多个控件。我只想垂直方向滚动,但是当我设置AutoScroll = true
时,我得到了水平和垂直滚动条。如何禁用水平滚动条并保留仅垂直滚动条的功能?
HorizontalScroll.Maximum = 0;
来禁用水平滚动条,并确保VerticalScroll.Visible = true;
以保留垂直滚动条的功能。水平滚动条应该消失。如果没有,请提供更多信息。
将AutoScroll设置为true。 将WrapContents设置为false。 将Padding Right设置为10。
对于我来说,这很好用。
以下是我如何实现在FlowLayoutPanel上具有多个标签和自动换行(WrapContents = true),并且只有垂直滚动条。
表单:
AutoScroll = True
FormBorderStyle = Sizable(default)
flowLayoutPanel1:
Anchor = Top, Left, Right
AutoSize = True
FlowDirection = TopDown
WrapContents = true
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;
}
}