在pictureBoxes

时间:2017-06-05 19:35:08

标签: c# winforms

表单大小拉伸到屏幕分辨率。表格中包含以下内容:

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 1

Image 2

问题:如何解决慢速绘制图片或让用户看不到的问题?

1 个答案:

答案 0 :(得分:1)

表单上还有一个属性可以启用双缓冲,有时可以解决显示问题(特别是如果您在绘制或进出表单时发现闪烁。这并不总是延伸到控件在窗体上(如Panel)。如果你想使用面板,你仍然可以进行双缓冲工作,但是你需要扩展面板然后使用扩展面板(我将共享代码) ,它很简单。。我怀疑如果我不得不猜测,如果将图片移出面板,你的工作开始加快,这也会有效。

<强>形式:

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);
        }
    }
}