簡體   English   中英

TableLayoutPanel的Autoscroll屬性不起作用

[英]Autoscroll property of TableLayoutPanel is not working

我想在TableLayoutPanel中動態添加行,並在GUI上的固定區域中添加。 所以,如果記錄數量增加,那么我想要一個垂直滾動條,幫助用戶查看更多記錄。 為此,我設置了Property AutoScroll = true; 但它不起作用。

CheckBox c = new CheckBox();
c.Text = "Han";
tableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
this.tableLayoutPanel1.RowCount = 1; this.tableLayoutPanel1.Controls.Add(c, 0, 0);
tableLayoutPanel1.AutoScrollPosition = new Point(0, tableLayoutPanel1.VerticalScroll.Maximum);
this.tableLayoutPanel1.AutoScroll = true;
tableLayoutPanel1.Padding = new Padding(0, 0, SystemInformation.VerticalScrollBarWidth, 0);

從另一個問題的評論中查看代碼,您似乎在每行添加行樣式,嘗試添加行而不添加樣式或首先添加一個樣式然后添加所有行。

  tableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
            tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));

            this.tableLayoutPanel1.Controls.Add(c);
            this.tableLayoutPanel1.Controls.Add(c1);
            this.tableLayoutPanel1.Controls.Add(c2);
tableLayoutPanel1.VerticalScroll.Maximum = 200;
            this.tableLayoutPanel1.AutoScroll = true;

因此你沒有發布你的代碼,我不能說你做錯了什么。 但這是您應該向表格布局面板添加控件的方式:

tableLayoutPanel.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
tableLayoutPanel.RowCount = tableLayoutPanel.RowStyles.Count;
YourCountrol control = new YourControl();
// setup your control properties
tableLayoutPanel.Controls.Add(control);
// scroll to the bottom to see just added control
tableLayoutPanel.AutoScrollPosition = 
    new Point(0, tableLayoutPanel.VerticalScroll.Maximum);

當然你應該有tableLayoutPanel.AutoScroll = true

順便說一句,為避免惱人的水平滾動條,您應該在表布局面板中添加正確的填充:

tableLayoutPanel.Padding = 
     new Padding(0, 0, SystemInformation.VerticalScrollBarWidth, 0);

應禁用tableLayoutPanel的UPDATE AutoSize 否則不會出現滾動 - 表格布局面板將會增長。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM