gpt4 book ai didi

c# - TableLayoutPanel 显示垂直滚动

转载 作者:可可西里 更新时间:2023-11-01 08:51:49 26 4
gpt4 key购买 nike

我有 TableLayoutPanel 用于通过 AutoScroll = true 动态创建控件。当我添加新控件时它工作正常。但是当我删除并且所有控件都可见时,垂直滚动是可见的。这里有一些截图:

预期/正确的滚动可见性:

enter image description here

不正确的可见性:

enter image description here

有什么想法吗?

更新:这是一些代码

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();

和删除代码

tableLayoutPanel1.SuspendLayout();
tableLayoutPanel1.Controls.Remove(item);
tableLayoutPanel1.RowStyles.RemoveAt(0);
tableLayoutPanel1.RowCount--;
tableLayoutPanel1.ResumeLayout();

AutoSize为真,AutoSizeMode为GrowAndShrink

最佳答案

问题涉及TableLayoutPanel scrolling .
您必须使用 Panel 来滚动而不是 TableLayoutPanel。
这是解决此问题的示例(用于垂直滚动):

  • 按如下方式设置您的 TableLayoutPanel 属性:
    • Dock = DockStyle.Top
    • AutoSize = true
    • AutoSizeMode = AutoSizeMode.GrowAndShrink
    • AutoScroll = false。
  • 将您的 TableLayoutPanel 放入具有以下属性的面板中:
    • Dock = DockStyle.Fill
    • 自动滚动 = true
    • AutoSize = false。

关于c# - TableLayoutPanel 显示垂直滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15620454/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com