Picturebox有时不会显示图像 [英] Picturebox sometimes doesnt show image

查看:253
本文介绍了Picturebox有时不会显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了简单的漫画阅读器,其中包含多个PictureBox,每个页面都包含图像。 PictureBox然后从上到下添加到flowlayoutpanel。

问题是有一些图像没有显示,当我调整图像显示的形式时。

屏幕图帮助



imglayout = FlowLayoutPanel



我的尝试:



i have create simple manga reader with multiple PictureBox to contain image each page. The PictureBox then added to flowlayoutpanel top to bottom.
The Problem is there's some image that doesnt show and when i resize the form the image showed.
Screenshoot to help

imglayout = FlowLayoutPanel

What I have tried:

chapterList.AddRange(Directory.GetDirectories("Gosu"));
            chapterList.Sort(new NumComparer());
            //load chapter pertama
            //simpan image di ram
            foreach (string item in Directory.GetFiles(chapterList[numChapter]))
            {
                imgList.Add(item);
            }
            imgList.Sort(new NumComparer());
            //buat picturebox
            this.SuspendLayout();
            foreach (string i in imgList)
            {
                Image img = Image.FromFile(i);
                PictureBox box = new PictureBox();
                box.Width = img.Width;
                box.Height = img.Height;
                box.BorderStyle = BorderStyle.FixedSingle;
                box.Image = img;
                if (boxwidth < img.Width) { boxwidth = img.Width; }
                imgLayout.Controls.Add(box);
            }
            this.Width = boxwidth+300;
            this.MinimumSize = new Size(boxwidth+300, 550);

推荐答案

将每个Boxex的SizeMode设置为缩放



在此方法结束时插入命令ResumeLayout(True)



也许它可能对发送Invalidate很有用到表格
Set the SizeMode of each of your Boxex to Zoom
and
at the end of this method insert the command ResumeLayout(True)
and
perhaps it could be useful to send an Invalidate to the Form


我看到了类似的事情,并且没有成功使用Suspend / Resume / PerformLayout的各种组合。最后我发现将图片框添加到隐藏面板是有效的,从那以后就没有问题了。我不能对这种方法的成功提供任何解释,所以要把它作为尝试的东西。



I have seen a similar thing and had no success with various combinations of Suspend/Resume/PerformLayout. Finally I found that adding the pictureboxes to a hidden panel was effective and have had no problems since. I can't offer any explanation for the success of this method so present it as something to try.

private void ShowAlbum(Image[] thumbnails) {
  List<PictureBox> pictureBoxList = new List<PictureBox>();
  foreach (Image img in thumbnails) {
    PictureBox box = new PictureBox();
    box.Image = img;
    pictureBoxList.Add(box);
  }

  flowPanel.Hide();
  flowPanel.Controls.AddRange(pictureBoxList.ToArray());
  // pbox handles are created when the container control is reshown
  flowPanel.Show();
}



Alan。


Alan.


这篇关于Picturebox有时不会显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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