black flicker when resizing

  • Thread starter Thread starter Thomas Richter
  • Start date Start date
T

Thomas Richter

Hi,
I can't get of the black flicker when I resize my form.
this = Mainform : System.Windows.Forms.Form
If I set the size from 300 to 500 I see for ca 500ms some
black areas. I try to solve it with:
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
But it doesn't work.

Mit freundlichen Grüßen aus Kiel

Thomas Richter
 
Thomas Richter said:
Hi,
I can't get of the black flicker when I resize my form.
this = Mainform : System.Windows.Forms.Form
If I set the size from 300 to 500 I see for ca 500ms some
black areas. I try to solve it with:
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
But it doesn't work.

That's because it doesn't do what you'd intuitively think it does.

What I assume you're thinking that does is the following

Create temp buffer.
Draw form and all controls in buffer
Copy buffer to screen

What's actaully happening is the following:

Create temp buffer
Draw form (without any controls) in buffer
Copy buffer to screen
Draw controls directly to screen

Unfortunately afaik there's no way to draw the form and all the controls it
contains in an offscreen buffer without writing all the paint code yourself.

If you're doing any manual resizing in the Resize or SizeChanged event
handlers try to reduce it as much as possible using anchoring and auto
resizing to do as much of the work as possible, it's much faster and
consequently smoother than trying to do the work yourself. In a recent
project I managed to work out ~80% (subjective) of the redraw flicker by
spending a day toying with the automatic resize functionality to reduce the
ammount of manual intervention needed.
 
I have managed to reduce a lot of flick on my gui which if made of bitmaps
and other graphics by using caret class here

using System;

using System.Runtime.InteropServices;

namespace WACLIENT

{

/// <summary>

/// Summary description for Carets.

/// </summary>

public class Carets

{

[DllImport("user32.dll")]

public static extern int ShowCaret(IntPtr hwnd);

[DllImport("user32.dll")]

public static extern int HideCaret(IntPtr hwnd);

public Carets()

{ }

}

}



use it as follows



Carets.HideCaret(this.Handle); //beginning of the code block

//code that does all and whatever

Carets.ShowCaret(this.Handle); //end of the code block

its a little processor consuming but works great
 
Raj Chudasama said:
Carets.HideCaret(this.Handle); //beginning of the code block

//code that does all and whatever

Carets.ShowCaret(this.Handle); //end of the code block

Just for clarification, this's supposed to be wrapping the manual
resize/layout code correct?

I'll give it a test tomorrow, since my flickering dialog does contain a fair
number of small bitmaps embedded in listviews.
 
Dan Neely said:
Just for clarification, this's supposed to be wrapping the manual
resize/layout code correct?

I'll give it a test tomorrow, since my flickering dialog does contain a fair
number of small bitmaps embedded in listviews.

I tried wrapping the form resize code with the caret calls but don't see any
difference. On my dev laptop the listview with the bitmaps flickers at the
edge of perception, and several text controls painted afterwards do flicker
annoyingly.
 
Back
Top