我有TableLayoutPanel用于动态创建AutoScroll = true的控件.添加新控件时,它工作正常.但是当我删除并且所有控件都可见时,可以看到垂直滚动.这里有一些截图:
预期/正确的滚动可见性:
可见性不正确:

有任何想法吗?
更新:这是一些代码
tableLayoutPanel1.SuspendLayout();
tableLayoutPanel1.RowCount = 0;
tableLayoutPanel1.RowStyles.Clear();
tableLayoutPanel1.AutoScroll = true;
tableLayoutPanel1.Padding = new Padding(0, 0, SystemInformation.VerticalScrollBarWidth, 0);
foreach (var item in objects)
{
tableLayoutPanel1.RowCount++;
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
tableLayoutPanel1.Controls.Add(CreateNewItem(item));
}
tableLayoutPanel1.RowCount++;
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
tableLayoutPanel1.Controls.Add(CreateAddButton());
tableLayoutPanel1.ResumeLayout();
Run Code Online (Sandbox Code Playgroud)
以及删除代码
tableLayoutPanel1.SuspendLayout();
tableLayoutPanel1.Controls.Remove(item);
tableLayoutPanel1.RowStyles.RemoveAt(0);
tableLayoutPanel1.RowCount--;
tableLayoutPanel1.ResumeLayout();
Run Code Online (Sandbox Code Playgroud)
AutoSize为true,AutoSizeMode为GrowAndShrink
c# scrollbar tablelayoutpanel vertical-scroll vertical-scrolling