简体   繁体   English

滚动条TableLayoutPanel c#

[英]scroll bar TableLayoutPanel c#

I have a TableLayoutPanel that has several TableLayoutPanels inside it.我有一个 TableLayoutPanel,里面有几个 TableLayoutPanel。 The amount changes dynamically and will almost always be too many to be able to fit inside the form.I need it to have a scroll bar so I can view the entire component.数量是动态变化的,而且几乎总是太多以至于无法容纳在表单中。我需要它有一个滚动条,以便我可以查看整个组件。

I have tried setting the autoscroll property on the main panel to true and docking it and/or setting a maximum size.我尝试将主面板上的 autoscroll 属性设置为 true 并将其停靠和/或设置最大尺寸。 What the controler does instead, is to try and fit ALL of the Panel inside the form therefore changing the size of its inside components and squeezing them all together instead of creating a scroll bar to scroll through my Panel.相反,控制器所做的是尝试将所有面板放入表单中,因此更改其内部组件的大小并将它们全部挤压在一起,而不是创建滚动条来滚动我的面板。

Do you guys know what I might be doing wrong?你们知道我可能做错了什么吗?

Thanks.谢谢。

Jose何塞

PS: I am using VS 2010 PS:我使用的是 VS 2010

I had the same issue one day and found out that the problem was that I had a "MinimumSize" set to the TableLayoutPanel.有一天我遇到了同样的问题,发现问题是我为 TableLayoutPanel 设置了“MinimumSize”。 That caused the control to keep a minimum height no matter what the Dock and/or Anchor constraints, preventing the AutoScroll feature to work properly.这导致无论 Dock 和/或 Anchor 约束如何,控件都保持最小高度,从而阻止 AutoScroll 功能正常工作。 Since that feature is based on a simple check on the Y coordinates of all children controls of a control against that control's height, the scrollbar was not appearing despite the fact the the TableLayoutPanel's child controls were "disapearing" out of sight due to its parent control clip area.由于该功能基于对控件的所有子控件的 Y 坐标与该控件的高度进行简单检查,因此尽管 TableLayoutPanel 的子控件由于其父控件而“消失”在视线之外,但滚动条并未出现剪辑区。

So in other words, check the MinimumSize property of TableLayoutPanel and make sure it's empty.因此,换句话说,检查 TableLayoutPanel 的 MinimumSize 属性并确保它为空。

Late answer, but I've been fighting with a complex layout recently and was looking for a solution to get my scrolling working on a screen with far too many fields.迟到的答案,但我最近一直在与复杂的布局作斗争,并且正在寻找一种解决方案来让我的滚动在包含太多字段的屏幕上工作。 Honestly, better design should avoid this problem 99% of the time but sometimes your hands are just tied.老实说,更好的设计应该可以在 99% 的情况下避免这个问题,但有时你的手只是被束缚了。

The Problem问题

The problem seems to be that if you're nested too deeply with multiple grids, groups, and panels they stop reporting properly to parent controls that their contents have overflown the size of the current screen.问题似乎是,如果您与多个网格、组和面板嵌套得太深,它们就会停止向父控件正确报告其内容已超出当前屏幕的大小。 Actually, the problem is probably that the controls are all set to dock fill and do fit within their parent control, so the top level control doesn't know that the contents of its great-great-great-great-grandchild controls don't fit.其实,这个问题也许在于控制都设置为停靠填充和他们的父母控制的范围内配合,所以上层控制不知道它的伟大伟大伟大伟大的孙子控件的内容不合身。

Solution解决方案

The trick to fix this seems to be manually forcing the top most panel to scroll at a certain minimum size:解决这个问题的技巧似乎是手动强制最顶部的面板以某个最小尺寸滚动:

MainPanel.AutoSize = true;
MainPanel.AutoScrollMinSize = new Size(400, 500);

Maybe this will help.也许会有所帮助。

if it still doesn't work, try put a panel and then put the tableLayoutPanel into that panel.如果它仍然不起作用,请尝试放置一个面板,然后将 tableLayoutPanel 放入该面板中。 Set to true the autoScroll property of the panel.将面板的 autoScroll 属性设置为 true。

I had the same thing happen on my project.我的项目也发生了同样的事情。 All my controls were squished inside the TableLayoutPanel.我所有的控件都被压缩在 TableLayoutPanel 中。 In my case, I was rendering many of the controls as ColumnStyle.Percent.就我而言,我将许多控件呈现为 ColumnStyle.Percent。 Switching this to ColumnStyle.Autosize was the fix I needed.将此切换到 ColumnStyle.Autosize 是我需要的修复。

I assume you've set these properties as well, but just in case my TableLayoutPanels also use the following settings:我假设您也设置了这些属性,但以防万一我的 TableLayoutPanels 也使用以下设置:

AutoSize = true;
AutoSizeMode = AutoSizeMode.GrowAndShrink;
AutoScroll = true;

TableLayoutPanel scrolling is full of bugs. TableLayoutPanel滚动充满了 bug。 The solution to make it work correctly is here .使其正常工作的解决方案在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM