填充FlowLayoutPanel的有大量的控制和对绘画的需求缩略图缩略图、需求、FlowLayoutPanel

由网友(m/m 隔心忘年°)分享简介:我试图使一个 ImageListBox 一种控制,将显示一个大量的缩略图,像Picasa使用一个。这是我设计的:我有一个 FlowLayoutPanel的填充了大量的用户控件对象,例如4000。每个用户控件分配一个委托为油漆事件。当油漆事件被调用时,它会检查内存缓存缩略图,如果图像不在缓存中,它将检索它从磁盘。我有...

我试图使一个 ImageListBox 一种控制,将显示一个大量的缩略图,像Picasa使用一个。

这是我设计的:

我有一个 FlowLayoutPanel的填充了大量的用户控件对象,例如4000。 每个用户控件分配一个委托为油漆事件。 当油漆事件被调用时,它会检查内存缓存缩略图,如果图像不在缓存中,它将检索它从磁盘。

我有我试图解决两个问题:

看来的WinForms将触发油漆事件,即使该用户控件不在视图。只有10个左右的控制实际上,鉴于外,其余都没有(在 FlowLayoutPanel.AutoScroll 设置为 )。其结果是,它试图检索缩略图的所有图像,并且需要很长的时间。

添加用户控件对象的 FlowLayoutPanel的需要稍微长的时间,约2-3秒。我可以忍受,但我不知道是否有更好的方法来做到这一点比:

 用户控件[]盒=新用户控件[N];
//填充阵列
panel.SuspendLayout();
panel.Controls.AddRange(箱);
panel.ResumeLayout();
 

解决方案 机场综合监控系统解决方案分析

要提高填充FlowLayoutPanel的与你的用户控件的速度,禁用布局更新,而你添加控件。

您立即循环之前,调用 SuspendLayout() ,然后在结束通话的 ResumeLayout() 。请务必使用一个try-finally保证 ResumeLayout()运行,即使发生异常。

I'm trying to make an ImageListBox kind of control that will display a large numbers of thumbnails, like the one that Picasa uses.

This is my design:

I have a FlowLayoutPanel that is populated with a lot of UserControl objects, for example 4,000. Each UserControl is assigned a delegate for the Paint event. When the Paint event is called, it checks a memory cache for the thumbnail and if the image is not in cache, it retrieves it from the disk.

I have two problems that I'm trying to solve:

It seems that WinForms will trigger a Paint event even if the UserControl is not in view. Only 10 or so controls are in fact in view, the rest are not (the FlowLayoutPanel.AutoScroll is set to true). As a result, it tries to retrieve thumbnails for all the images and that takes a long time.

Adding the UserControl objects to the FlowLayoutPanel takes a somewhat long time, about 2-3 seconds. I can live with it but I'm wondering if there is a better way to do it than:

UserControl[] boxes = new UserControl[N];
// populate array
panel.SuspendLayout();
panel.Controls.AddRange(boxes);
panel.ResumeLayout();

解决方案

To improve the speed of populating the FlowLayoutPanel with your user controls, disable layout updating while you add the controls.

Immediately before your loop, call SuspendLayout() and then at the end call ResumeLayout(). Make sure to use a try-finally to guarantee the ResumeLayout() runs even if an exception occurs.

阅读全文

相关推荐

最新文章