title: C# Multiple picturebox initialisation issue
body: <p>I am putting together an application that uses more than one picturebox on the GUI.  I have written custom events for each picturebox that are called on paint events.</p>
  
  <p>Unfortunately, when the application runs, precisely one picturebox displays properly.  The others simply display as white boxes.  Whichever opicturebox happens to be added first in form.designer is the picturebox that displays properly, for the others their paint events are never triggered.  I have tried to get around this by calling various combinations of picturebox.refresh(), picturebox.update() and picturebox.invalidate() in the form constructor, to no avail.</p>
  
  <p>Interestingly, when I associate a button press event with picturebox.refresh() and picturebox.update() and press the button once the program is running, the pictureboxes start behaving as normal - the paint event is called and the image updates.</p>
  
  <p>Does anyone have any ideas how I can get all of the pictureboxes to display properly on initialisation?</p>
  
  <p>Code snippets that may be useful:</p>
  
  <p>Paint code for the pictureboxes:</p>
  
  <pre><code>private void PictureBox1_Paint(object sender, PaintEventArgs e)
  {
      paintPictureBox(e, PictureBox1, currentImage[0]);
  }
  
  private void paintPictureBox(PaintEventArgs e, PictureBox picBox,ImageObject c)
  {
      try
      {
          Font myFont = new Font("Arial", 14);
          //Get bitmap
          Bitmap imageToDisplay = new Bitmap(Bitmap.FromFile(c.ImageFile));
          //resize smallest dimension to 200
          if (imageToDisplay.Height &gt; imageToDisplay.Width)
          {
              imageToDisplay = new Bitmap(Bitmap.FromFile(c.ImageFile), 200, 200 * imageToDisplay.Height / imageToDisplay.Width);
          }
          else
          {
              imageToDisplay = new Bitmap(Bitmap.FromFile(c.ImageFile), 200 * imageToDisplay.Width / imageToDisplay.Height, 200);
          }
          //crop anything outside of 200x200
          imageToDisplay = imageToDisplay.Clone(new Rectangle(Math.Max((imageToDisplay.Width - 200) / 2, 0), Math.Max((imageToDisplay.Height - 200) / 2, 0), 200, 200), imageToDisplay.PixelFormat);
          //now draw it
          picBox.Image = imageToDisplay;  
          //add the name
          e.Graphics.DrawString(c.Name, myFont, Brushes.Maroon, new Point(2, 200));
      }
      catch (Exception E)
      {
          MessageBox.Show("Could not display image successfully\n" + E.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
  }
  </code></pre>
  
  <p>Code from form.designer:</p>
  
  <pre><code>    //This one displays correctly on initialisation
      this.Controls.Add(this.PictureBox0);
      //These two do not
      this.Controls.Add(this.PictureBox1);
      this.Controls.Add(this.PictureBox2);
      ((System.ComponentModel.ISupportInitialize)(this.PictureBox0)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.PictureBox1)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.PictureBox2)).EndInit();
  </code></pre>
  
  <p>Code for button press that makes pictureboxes display correctly (after initialisation):</p>
  
  <pre><code>private void Button_Click(object sender, EventArgs e)
  {
      //Refresh the picture boxes
      foreach (PictureBox pb in this.Controls.OfType&lt;PictureBox&gt;())
      {
          pb.Refresh();
          pb.Update();
      }
  }
  </code></pre>