我想在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;
关于c# - TableLayoutPanel的Autoscroll属性不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14019828/