面板自动滚动不起作用 [英] Panel Autoscroll not working

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

问题描述

在我的C#4.0 Forms程序中,我试图在每个项目上使用标签和按钮来近似列表框。

我正在使用主面板,autoscroll = true,并以编程方式添加子面板到主面板。

子面板几乎与主面板一样宽,位于彼此之下,因此垂直滚动用于查看所有子面板(如列表框)。

每次显示主面板(visibility = true)时,都会调用Panel.Contols.Clear函数,然后根据需要添加子面板。这在第一次工作正常!

问题是,如果主面板在其可见性设置为false时完全向下滚动,则下次显示主面板时,从顶部滚动的子面板将不显示。

我试过将autoscroll设置为false然后回到true。



Chris

In my C# 4.0 Forms program I am trying to approximate a list box with labels and buttons on each item.
I am using a main panel, with autoscroll = true, and programmatically adding sub panels to the main panel.
The sub panels are almost as wide as the main panel and located below each other so that the vertical scroll is used to see all the sub panels (like a list box).
Each time the main panel is shown (visibility = true) the Panel.Contols.Clear function is called then sub panels are added as needed. This works fine the first time!
Problem is if the main panel is scrolled down at all when its visibility is set to false next time the main panel is shown the sub panels that were scrolled off the top will not show.
I have tried setting autoscroll to false then back to true.

Chris

推荐答案

据我所知,Autoscroll与此无关。



尝试枚举Controls集合并在所有上设置Visible属性子面板为True。
As far as I can see, Autoscroll has nothing to do with this.

Try enumerating the Controls collection and setting the Visible property on all the sub-panels to True.


我添加了设置Vericalscroll.Value = 0

所以代码是这样的。



myScrollablePanel.Vericalscroll.Value = 0; //这是修复

myScrollablePanel.Controls.Clear();

for(...)

{

...

myScrollablePanel.Controls.Add(m_MySubPanels [i]);

...

}



现在总是显示myScrollablePanel的顶部,如果合适,垂直滚动和我的上子面板



注意:每次myScrollablePanel它是可见的它有一套新的控件。



谢谢

Chris
I added setting Vericalscroll.Value = 0
So code goes something like this.

myScrollablePanel.Vericalscroll.Value = 0; // this is the fix
myScrollablePanel.Controls.Clear();
for(...)
{
...
myScrollablePanel.Controls.Add(m_MySubPanels[i]);
...
}

Now always shows top of myScrollablePanel, the vertical scroll if appropriate and my upper sub panels

Note: Each time myScrollablePanel is made visible it has a new set of controls on it.

Thanks
Chris


这篇关于面板自动滚动不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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