繁体   English   中英

按需将图像加载到 FlowLayoutPanel 中?

[英]Load images on demand into FlowLayoutPanel?

我想用许多图像(~400pc.,500x500px)填充 flowlayoutpanel。 我遍历带有文件名的字符串列表,并将这些图片添加到 flp。 但是在大约 200 张图像以上,面板不会显示更多图像。

我认为这是一个性能问题,我想问一下,是否可以“按需”加载图像?

喜欢滚动面板并只加载“可见”图像?

对于面板填充,我使用这个:

public void PanelFill(List<string> filenames)
{
    try
    {
        int temp = 0;
        foreach (string filename in filenames)
        {
            GC.Collect();
            PictureBox pic = new PictureBox
            {
                ClientSize = new Size(int_thumbWidth, int_thumbHeight),
                //Image = new Bitmap(filename),
                Tag = filename,
                BorderStyle = BorderStyle.FixedSingle
            };
            if ((pic.Image.Width > int_thumbWidth) ||
                (pic.Image.Height > int_thumbHeight))
            {
                pic.SizeMode = PictureBoxSizeMode.Zoom;
            }
            else
            {
                pic.SizeMode = PictureBoxSizeMode.CenterImage;
            }
            flowLayoutPanel_esww_bildvergleich.Invoke(new Action(() => { pic.Parent = flowLayoutPanel_esww_bildvergleich; }));
            pic.Click += PictureBox_Click;
            pic.DoubleClick += PictureBox_DoubleClick;
            pic.MouseUp += PictureBox_MouseUp;
            temp++;
        }
    }
    catch (OutOfMemoryException)
    {
        MessageBox.Show("Es wurden zu viele Fotos gefunden. Der Arbeitsspeicher ist nicht ausreichend. Bitte passen Sie Ihre Filter an.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
        str_aufnahmeTyp.Clear();
    }
    catch (Exception ex)
    {
        Fehlerbehandlung.Fehler(-1, ex.Message);
    }
}

我的一个解决方法是添加一个 Scroll/MouseEnter-Eventhandler 来捕捉面板的滚动。 在处理程序中,我使用 .PerformLayout()

 this.flowLayoutPanel_esww_bildvergleich.MouseEnter += new System.EventHandler(this.flowLayoutPanel_esww_bildvergleich_MouseEnter);

和...

        private void flowLayoutPanel_esww_bildvergleich_MouseEnter(object sender, EventArgs e)
    {
        flowLayoutPanel_esww_bildvergleich.Focus();
        flowLayoutPanel_esww_bildvergleich.PerformLayout();
    }

暂无
暂无

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

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