簡體   English   中英

如何在 FlowLayoutPanel 中禁用水平滾動條?

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

我有一個 FlowLayoutPanel,上面有多個控件。 我只想在垂直方向滾動。 但是當我設置AutoScroll = true ,我得到了垂直和水平滾動條。 如何禁用水平滾動條而只保持垂直滾動條正常工作?

  • 自動滾動設置為 true
  • WrapContents設置為 false。
  • 確保尺寸大於控件的寬度加上垂直滾動條的寬度。

水平滾動條應該消失。 如果沒有,請提供更多信息。

將 AutoScroll 設置為 true。 將 WrapContents 設置為 false。 將 Padding Right 設置為 10。

這對我來說很好用。

這是我如何實現在 FlowLayoutPanel 上有多個標簽,並帶有換行文本(WrapContents = true),僅限垂直滾動條。

  1. 我在表單上有一個 flowLayoutPanel1
  2. 如下設置 form 和 flowLayoutPanel1 的屬性:

形式:

AutoScroll = True
FormBorderStyle = Sizable(default)

flowLayoutPanel1:

Anchor = Top, Left, Right
AutoSize = True
FlowDirection = TopDown
WrapContents = true
  1. 在表單類上實現此代碼以進行測試

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

垂直滾動條在起作用

        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