1

I am making a simple game that (for the main part) consists of a Panel with a grid of 32 PictureBoxes inside, each with a BackgroundImage. You click on a "tile" and it flips revealing a picture. My problem is that when the Form Loads, I can see it drawing. I see the Panel .. then empty PictureBoxes, then finally it fills in the PictureBoxes with the BackgroundImages.

I've turned DoubleBuffer to True for the Form, and I've also added the following:

Private Sub UseDoubleBuffer()

    Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
    Me.UpdateStyles()

End Sub

Which I call when the Form Loads. I'm not sure what else I can do? I want it to just 'pop' onto the screen. Why isn't the DoubleBuffer working? Do I need to code the panel manually? I was trying to avoid that as it's obviously easier to just drag and drop into the Form, but if I need to, I will.

I can't post screenshots apparently, as my rep isn't high enough yet, but believe me, it looks hideous, and I do want to make this as sleek as I possible can. Any ideas?

Jayce
  • 539
  • 6
  • 21
  • I think this has been answered here: [How do I disable updating a form in Windows Forms][1] [1]: http://stackoverflow.com/questions/126876/how-do-i-disable-updating-a-form-in-windows-forms – dadkind Apr 20 '15 at 22:42
  • 2
    The image you assigned to the BackgroundImage property is far too large, resizing it to fit the small picture boxes takes too long. So you see them getting drawn one by one. Create a better one with a painting program, one that fits. If it still takes too long (it shouldn't) then you can use [this hack](http://stackoverflow.com/a/3718648/17034). – Hans Passant Apr 20 '15 at 22:53

2 Answers2

0

Try creating flicker free custom panel controls:

Here are the steps to use this control: 1. Add new class "NonFlickerPanel" to your C# application. 2. Replace autogenerated class code with C# code shown below. 3. Use NonFlickerPanel object instead of Panel object in your application.

public partial class NonFlickerPanel : Panel
{
   public NonFlickerPanel() : base()
   {
          this.SetStyle(ControlStyles.AllPaintingInWmPaint,
                              ControlStyles.UserPaint 
                              ControlStyles.OptimizedDoubleBuffer, 
                              true);
   }
}
-1

Try making the picture boxes invisible (.visible = false) until they're all loaded, then set visible to true for all of them.

xpda
  • 15,585
  • 8
  • 51
  • 82
  • Excellent. Rather than making all of the Pictureboxes invisible, I tried making the Panel invisible instead and setting the .Visible to True in the Load after my Call DoubleBuffer() statement and it works! – Jayce Apr 21 '15 at 06:48