2017-06-05 65 views
0

表格大小拉伸至屏幕分辨率。表单中包含以下元素:在图片框中缓慢绘制图片

private System.Windows.Forms.PictureBox pictureBox6; 
private System.Windows.Forms.PictureBox pictureBox7; 
private System.Windows.Forms.PictureBox pictureBox8; 
private System.Windows.Forms.PictureBox pictureBox1; 
private System.Windows.Forms.PictureBox pictureBox9; 
private System.Windows.Forms.PictureBox pictureBox3; 
private System.Windows.Forms.Label label1; 
private System.Windows.Forms.Label label2; 
private System.Windows.Forms.Timer timer1; 
private System.Windows.Forms.PictureBox pictureBox2; 
private System.Windows.Forms.Button button1; 
private System.Windows.Forms.PictureBox pictureBox4; 
private System.Windows.Forms.Label label3; 
private System.Windows.Forms.Panel panel1; 

当您打开窗体时,它会立即将图像从文件夹加载到面板。例如:

pictureBox2.Load("bgr/1.png"); 

图像加载和显示,但他们得出了很长时间,也就是说,你可以看到图像本身零件的绘制。

Image 2

问:我怎样才能解决慢绘制图像的问题或使其对用户不可见?

+0

都比他们要显示的PictureBoxes更大的图像?图像越大,渲染时间就越长...... – adv12

+0

@ adv12不,pictureBoxes比图像稍大 –

+0

查看一些关于PictureBoxes的建议[here](https://stackoverflow.com/questions/2151456/winforms -performance-mystery-derived-picturebox-control-slow-the-origina)和[here](https://stackoverflow.com/questions/28689358/slow-picture-box)和[here](https:/ /stackoverflow.com/questions/3567558/display-picture-box-faster) –

回答

1

还有窗体上的属性来启用双缓冲,有时可以解决显示问题(特别是如果你发现在绘制或进出形式的闪烁。这并不总是向下延伸到(如面板),如果你想使用面板,你仍然可以做双缓冲工作,但你需要扩展面板,然后使用扩展面板(我将分享代码,这很简单)。我想,如果我猜,如果通过移动画面出屏你的工作开始加快,这也将工作

方式:

this.DoubleBuffered = true; 

扩展面板:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace MyApp 
{ 
    public class PanelEx : System.Windows.Forms.Panel 
    { 
     public PanelEx() 
     { 
      this.SetStyle(
       System.Windows.Forms.ControlStyles.UserPaint | 
       System.Windows.Forms.ControlStyles.AllPaintingInWmPaint | 
       System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer, 
       true); 
     } 
    } 
} 
+0

非常感谢!这解决了我的问题。 –

+0

不客气,很高兴提供帮助。 –