Annoying flickering problem

M

Maya

Hi all,

We have a windows forms application with different controls used
inside, each control has several input items such as textboxes and some

treeviews.. etc.


We have been trying to eliminate flickering issues when loading
different controls or switching to different views with no luck, and
have been trying different suggested methods to get rid of the
flickering such as:
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
- this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
- SuspendItemsLayout();
- ResumeItemsLayout();


Unfortunately using the above code in each control or the main form
didn't help too, I'm wondering desperately if there is another way to
fix this annoying problem?


FYI: We are using Visual Studio 2005 / .NET 2.0 running on mainly
Windows XP Professional SP2 on 3GHz multithreaded CPU and 1GB RAM.


Thanks for your help.


Maya
 
M

mail

Hi Maya,

Flickering is an annoyance and sometimes requires a bit of patience and
investigation to eliminate.

Yes use SuspendLayout() / ResumeLayout() to wrap insertion removal and
change of controls. When you call Resumelayout it does not often need
a true parameter.

Do a code review and check for how often, and necessary calls to
Refresh() Invalidate()/ Update() and PerformLayout() are made.

Check you are not using docking styles and wrestling with them in code
for performing layouts!

If you own the controls you are using - code review these - make sure
they behave in their own right. In any case test them on their own in
a separate simple windows app to understand them properly.

Like you've mentioned use SetStyle - appropriately for your own
controls

this.SetStyle ( System.Windows.Forms.ControlStyles.DoubleBuffer, true
);

this.SetStyle ( System.Windows.Forms.ControlStyles.UserPaint, true );

this.SetStyle (
System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true );

- If you are doing all the painting and drawing - and If you're doing
the lot then override OnPaint, OnPaintBackground and test not calling
the base methods. You don't want the base to fill the control with a
nice gray background every time you change a pixel!

and I've found:

this.SetStyle ( System.Windows.Forms.ControlStyles.ResizeRedraw , false
);

can be useful.

All the above are not instant cures on their own, but once you have a
clear understanding of the flow of things in your app, they are the
tools and methods to get it right. Hope you cure it quickly.
 
C

chanmm

You have some treeviews in a single form? That might not be a good idea
though.

chanmm
 
A

alikreznik

Usually this happens because you don't include BeginUpdate and
EndUpdate calls when populating, so whats happening is after every
update, the screen gets repainted. To eliminate that, before your
populate loops put BeginUpdate and after put EndUpdate

so, you should do something like treeview.BeginUpdate () and
treeview.EndUpdate () once you are done
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top