![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
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://msdn.microsoft.com/subscripti...ult.aspx#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://msdn.microsoft.com/subscripti...t/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
Hi Richard, Thank you for your prompt reply! Sorry that I made a mistake in my previous reply, i.e. I said the ListView in .NET 1.x doesn't support double buffering. In fact, the ListView class in .NET Framework is a wrapper of the native ListView control and the native ListView control on Windows XP and later supports double buffering. Although the ListView in .NET 1.x doesn't provide the DoubleBuffered property, we can use Win32 API SendMessage function to set the ListView to use double buffering. To use the native ListView control, call Application.EnableVisualStyles before you start your main message loop in the static Main method. The following is a sample: public class Form1 : System.Windows.Forms.Form { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.Run(new Form1()); } } public class MyListView:ListView { const int LVM_FIRST=0x1000; const int LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST+54; const int LVS_EX_DOUBLEBUFFER = 0x10000; [DllImport("user32.dll")] static extern int SendMessage(IntPtr hWnd, int msg, int wParam,int lParam); public MyListView() { this.SetStyle(ControlStyles.DoubleBuffer,true); } public void SetDoubleBuffered() { SendMessage(this.Handle,LVM_SETEXTENDEDLISTVIEWSTY LE,LVS_EX_DOUBLEBUFFER,LVS _EX_DOUBLEBUFFER); } protected override void OnHandleCreated(System.EventArgs e) { base.OnHandleCreated (e); this.SetDoubleBuffered(); } } Note that the above workaround only applies to Windows XP and later. Please try it in your project to see if it solves the problem and let me know the result. Sincerely, Linda Liu Microsoft Online Community Support |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
Hi Richard, Thank you for your feedback and I am glad to hear that the problem is fixed. I will make a suggestion to our documentation team about including this tip in the documentation. Thank you for reminding and support for Microsoft! If you have any other questions in the future, please don't hesitate to contact us. It's always our pleasure to be of assistance! Sincerely, Linda Liu Microsoft Online Community Support |
#8
| |||
| |||
|
#9
| |||
| |||
|
|
Hi Richard, I performed a test based on your description on my Windows XP machine and did see the problem. I searched in our internal database and found that this is a known issue in Windows XP. The possible workaround to this problem would have been to custom draw the ListView control if the ListView in .NET 1.x supported custom drawing. Unfortunately, in fact the ListView in .NET 1.x doesn't support custom drawing at all. I will consult this problem in our internal discussion group to see if there's any workaround. In addition, if you could upgrade to .NET 2.0, the problem will not exist. Sincerely, Linda Liu Microsoft Online Community Support |
#10
| |||
| |||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |