1

I have a form which displays several graphics and in order to improve the visual experience while the graphics are rendered I have used this piece of code that enables Double Buffering.

When I execute the application without minimizing/maximizing the form, the Double Buffering works excellent, but if I happen to minimize the form and maximize it again, now the Double Buffering doesn't work anymore and the graphics get repainted with a visible flickering.

So is there a way to turn on Double Buffering every time the form gets minimized/maximized?

Community
  • 1
  • 1
codeaviator
  • 2,545
  • 17
  • 42

1 Answers1

1

try this code

bool hasMinimized;
void SizeChangedCallback(object sender, EventArgs e) {
    if ( WindowState == FormWindowState.Minimized ) {
        hasMinimized = true;
    } else {
        if ( hasMinimized ) {
            hasMinimized = false;
            /* Call SetStyle() in here */
        }
    }
}

you have to link Form's SizeChanged event to SizeChangedCallback.
like this:

this.SizeChanged += SizeChangedCallback;
SlaneR
  • 684
  • 5
  • 19
  • This code only controls the `WindowState` property of the form, but doesn't do anything related with double buffering. Where and how should I call the `protected override CreateParams CreateParams` method in your code? – codeaviator Jun 29 '15 at 01:42
  • If you are asking about how to call `protected override CreateParams CreateParams`, your question is wrong. `CreateParams` property is only accessed at once when form's creation. To overriding `CreateParams`, open your Form's source code and type [this code](http://stackoverflow.com/questions/3718380/winforms-double-buffering/3718648#3718648) or you can replace `/* Call SetStyle() in here */` to `SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);` – SlaneR Jun 29 '15 at 06:26
  • hope this help to you – SlaneR Jun 29 '15 at 06:26
  • I followed all your instructions but nothing has changed at all with regard to the flickering. – codeaviator Jun 29 '15 at 09:49
  • Can you provide me a piece of code to prevent the flickering? (Form) – SlaneR Jun 30 '15 at 02:20
  • Double buffering with SetStyle is NOT the same as double buffering with CreateParams, in forms with many controls the create params solution is radically better – Eduardo Wada Jun 30 '15 at 19:02