TableLayoutPanel显示垂直滚动 [英] TableLayoutPanel displays vertical scroll

查看:507
本文介绍了TableLayoutPanel显示垂直滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有用于自动创建AutoScroll = true控件的TableLayoutPanel.当我添加新控件时,它工作正常.但是,当我删除并且所有控件都可见时,垂直滚动可见. 此处的一些屏幕截图:

I have TableLayoutPanel for dynamic creation of controls with AutoScroll = true. It's work fine when I add new controls. But when I remove and all controls are visible, vertical scroll is visible. Some screenshots here:

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

Expected/correct scroll visibility:

可见性不正确:

有什么想法吗?

更新: 这是一些代码

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为true,AutoSizeMode为GrowAndShrink

AutoSize is true, AutoSizeMode is GrowAndShrink

推荐答案

问题与

The problem concerns TableLayoutPanel scrolling.
You have to use a Panel for scrolling instead of TableLayoutPanel.
Here is an example to solve this problem (for vertical scrolling) :

  • 按如下所示设置TableLayoutPanel属性:
    • Dock = DockStyle.Top
    • AutoSize = true
    • AutoSizeMode = AutoSizeMode.GrowAndShrink
    • AutoScroll = false.
    • Set your TableLayoutPanel properties as follow :
      • Dock = DockStyle.Top
      • AutoSize = true
      • AutoSizeMode = AutoSizeMode.GrowAndShrink
      • AutoScroll = false.
      • Dock = DockStyle.Fill
      • AutoScroll = true
      • AutoSize = false.

      这篇关于TableLayoutPanel显示垂直滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆