我正在尝试动态创建按钮并将它们添加到表格布局面板问题是无论我做什么我都会保持垂直滚动条即使我只有一行按钮。 代码:
private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < 50; i++)
{
Button button = new Button();
// button.Location = new Point(20, 30 * i + 10);
button.Click += new EventHandler(ButtonClick);
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
tableLayoutPanel1.ColumnCount += 1;
tableLayoutPanel1.Controls.Add(button);
}
}
结果:
我想摆脱水平的一切
提前致谢
答案 0 :(得分:3)
尝试将水平滚动条的高度添加到控件的填充:
private void button2_Click(object sender, EventArgs e)
{
tableLayoutPanel1.Padding = new Padding(0, 0, 0, SystemInformation.HorizontalScrollBarHeight);
for (int i = 0; i < 50; i++)
{
Button button = new Button();
button.Click += new EventHandler(ButtonClick);
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 20F));
tableLayoutPanel1.ColumnCount += 1;
tableLayoutPanel1.Controls.Add(button);
}
}
答案 1 :(得分:2)
tableLayoutPanel1.VerticalScroll.Enabled = false;
应该摆脱你的问题
答案 2 :(得分:0)
我通过填充我的TableLayoutPanel控件来解决问题,以解释VeritcalScrollBarWidth。
这是VB.net,但你明白了这一点:
'Prevent Constant Horizontal Scrollbar by padding for the VerticalBar
MyTableLayoutPanel.Padding = New Padding(0, 0, SystemInformation.VerticalScrollBarWidth, 0)