0

The form size is stretched to the screen resolution. The following elements are on the form:

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;

When you open a form, it immediately loads the images to the panel from the folder. Example:

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

Images are loaded and displayed, but they are drawn for a long time, that is, you can see the rendering of the image itself in parts.

Image 1

Image 2

Question: how can I solve the problem of slow drawing images or make it invisible to the user?

Community
  • 1
  • 1
excelsiorious
  • 422
  • 9
  • 18
  • Are the images much larger than the PictureBoxes in which they're displayed? The larger the image, the longer it will take to render.... – adv12 Jun 05 '17 at 19:37
  • @adv12 no, pictureBoxes are slightly larger than images – excelsiorious Jun 05 '17 at 19:53
  • Check some advises regarding PictureBoxes [here](https://stackoverflow.com/questions/2151456/winforms-performance-mystery-derived-picturebox-control-slower-than-the-origina) and [here](https://stackoverflow.com/questions/28689358/slow-picture-box) and [here](https://stackoverflow.com/questions/3567558/display-picture-box-faster) – sasha_gud Jun 05 '17 at 20:07
  • You should just use one picturebox at most (or even a panel, etc) and draw each image onto one. Here's a quick example for saving, but could be change to just reflect the image inside a picturebox): https://stackoverflow.com/questions/32746695/drawing-2-bitmaps-in-one-picturebox – Troy Mac1ure Jun 05 '17 at 21:34
  • Do you mean it is fat when loading and slow when resizing or is it slow from the beginning? It shouldn't unless the images come from a slow drive. Any code in the resizing? – TaW Jun 06 '17 at 07:47
  • Thank you all! The tips partially accelerated the drawing. – excelsiorious Jun 06 '17 at 16:31

1 Answers1

1

There is also a property on the form to enable double buffering that can sometimes fix display issues (particularly if you notice flickering while drawing or going in and out of a form. This doesn't always extend down to the controls on the form (like the Panel). If you want to use the panel, you can still make double buffering work but you'll need to extend the panel and then use the extended panel (I'll share the code, it's straightforward). I suspect if I had to guess that if by moving the pictures out of the panel yours started working faster that this will also work.

Form:

this.DoubleBuffered = true;

Extended Panel:

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);
        }
    }
}
b.pell
  • 3,873
  • 2
  • 28
  • 39