.NET FW v1.1 Listview flickering issue

.NET FW v1.1 Listview flickering issue

Post by UmljaGFyZ » Sat, 17 Nov 2007 23:33:01


Hello community,

I need a way to reduce flickering of the listview in .NET FW v1.1.

The case: I have a listview control hosted in a plain form that has 20 rows
and 5 columns. The data for a few of these rows changes often, about 2 times
per second. The effect: the listview flickers each row where the data has
been updated. If a window partial covers the listview, then the entire
listview flickers, regardless whether any data within it has changed.

I have tried several combinations of DoubleBuffer, UserPaint,
AllPaintingInWmPaint, WM_SETREDRAW, LockWindowUpdate, etc... even tried
doing a side-by-side of the listview between 1.1 and 2.0 (fails due to
imcompatibility of CLR), ... and nothing seems to help.

In .NET 2.0, All is fine once I apply the OptimizedDoubleBuffer.

Any way to do this? What can be done to achieve the same effects of the
OptmizedDoubleBuffer in .NET 2.0, but in .NET FW v1.1?

Thank you,
 
 
 

.NET FW v1.1 Listview flickering issue

Post by v-lli » Tue, 20 Nov 2007 16:47:15

Hi Richard,

The ListView in .NET 1.x doesn't support double buffering. So it's no use
setting the DoubleBuffer style to true for the ListView in .NET 1.x.

In fact, the reason why the ListView flickers when it is updated frequently
is that the WM_ERASEBKGND message is sent to the ListView every time the
ListView needs redrawing. Thus, the ListView items are erased with the back
color first and then redraw the text in them.

To reduce the flickering, we can intercepting the WM_ERASEBKGND message in
the WndProc method of a ListView derived class and clip all the bounds of
the ListView items out of the drawing region, so that the bounds of the
ListView items will not erased with back color and the flickering
disappears.

The following is a sample code:

using System.Windows.Forms;
using System.Drawing;

public class MyListView:ListView
{
int WM_ERASEBKGND=0x14;

protected override void WndProc(ref Message m)
{
if(m.Msg == WM_ERASEBKGND)
{
Color backColor = Enabled ? BackColor :
Color.FromKnownColor(KnownColor.Control);
// create a graphics object using the supplied handle to the device
context.
Graphics graphics = Graphics.FromHdc(m.WParam);
// clip all of the list view items out of the drawing region
foreach (ListViewItem item in Items)
{
graphics.ExcludeClip(new Rectangle(item.Bounds.Left +
2,item.Bounds.Top,item.Bounds.Width-2,item.Bounds.Height));
}
// now paint what's left with the background color
using(SolidBrush brush = new SolidBrush(backColor))
{
graphics.FillRegion(brush, graphics.Clip);
graphics.Dispose();
}
}
else
{
base.WndProc (ref m);
}
}

}

The above code works well on my side. Please try it in your project to see
if it could solve the problem and let me know the result.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://www.yqcomputer.com/ #notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://www.yqcomputer.com/
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
 
 

.NET FW v1.1 Listview flickering issue

Post by UmljaGFyZ » Thu, 22 Nov 2007 03:55:01

Hello Linda,

Yes that did the trick. Thank you. It be nice to have this included in the
documentation!

Richard
 
 
 

.NET FW v1.1 Listview flickering issue

Post by UmljaGFyZ » Sat, 01 Dec 2007 23:59:00

Hello Linda,

The fix is OK until it made it to quality testing. The fix actually breaks
icons in listviews and treeviews all over. Listviews that have icons now
eeither do not show them altogether or show the wrong ones.

Please advise, thank you,

Richard
 
 
 

.NET FW v1.1 Listview flickering issue

Post by v-lli » Tue, 11 Dec 2007 12:09:57

Hi Richard,

Thank you for your feedback!

If an application is enabled visual styles by calling the
Application.EnableVisualStyles, .NET Framework will draw controls with
visual styles.

If there's a problem in drawing controls with visual styles, e.g. in our
case, the icons don't appear in the ListView when the visual styles is
enabled for the application, calling the Application.DoEvents can always
solve the problem.

If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
 
 

.NET FW v1.1 Listview flickering issue

Post by UmljaGFyZ » Wed, 12 Dec 2007 13:11:01

Hello Linda,

Well, EnableVisualStyles does have a side effect with toolbars. The toolbar
offers a property ButtonSize, which can be set when EnableVisualStyles is not
called. When the EnableVisualStyles is called, the toolbar buttons simply
ignore the specified size. They automatically get to be the size of the
content of the toolbar button.

Please advise on how to not have unwanted side effect on the toolbar
(buttons)...

Thank you,

Richard
 
 
 

.NET FW v1.1 Listview flickering issue

Post by v-lli » Wed, 12 Dec 2007 19:14:21

Hi Richard,

I performed a test on this issue and did reproduce the problem on my side.

I searched in our internal data base and found that this is a known issue.
Unfortunately, there's no workaround so far.

I suggest that you use the Panel and Button to mimic the ToolBar, i.e. add
some Buttons on a Panel and dock the Panel to the top of the form. If you
don't like the Button to be rendered with visual styles, you may set the
FlatStyle property of the Button to a value other than System.

Hope this helps.

If you have any concern, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
 
 

.NET FW v1.1 Listview flickering issue

Post by UmljaGFyZ » Fri, 14 Dec 2007 23:14:00

Hello Linda,

Well, our framework "owns" the message loop creation (application.run),
thereby we do the enablevisualstyles, which break their applications.

Anyhow, I'll what can be done...

Richard
 
 
 

.NET FW v1.1 Listview flickering issue

Post by v-lli » Sat, 15 Dec 2007 19:44:19

Hi Richard,


What's the "framework" you mentioned in the above sentence? What do you
mean by "owns the message loop creation"?


Do you mean that you couldn't enable visual styles in the application
because that would break the application?

Sincerely,
Linda Liu
Microsoft Online Community Support
 
 
 

.NET FW v1.1 Listview flickering issue

Post by UmljaGFyZ » Sat, 15 Dec 2007 23:22:01

Well it is a catch22 - to solve the listview problem, I need to
enablevisualstyles, but then that breaks their applications' icons.

"by framework" I mean a framework that we provide so that they can build
their specialized applications.