【问题标题】:Load images on demand into FlowLayoutPanel?将图像按需加载到 FlowLayoutPanel 中?
【发布时间】:2020-02-14 06:19:05
【问题描述】:

我想用许多图像(〜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);
    }
}

【问题讨论】:

    标签: c# performance flowlayoutpanel


    【解决方案1】:

    我的一个解决方法是添加一个 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();
        }
    

    【讨论】:

      猜你喜欢
      • 2021-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多