C # Flashing resolution for updating data with ListView
When you use the VS Auto control ListView Control, The flash occurs when you update some of the code inside
After settlement:
Workaround use double buffering: Add a new class to inherit the ListView to override it
1 Public classDoublebufferlistview:listview2 {3 PublicDoublebufferlistview ()4 {5SetStyle (Controlstyles.doublebuffer |6Controlstyles.optimizeddoublebuffer |7Controlstyles.allpaintinginwmpaint,true);8 updatestyles ();9 }Ten}
Create a new demotest test
1. Add an instance of Doublebufferlistview
Doublebufferlistview doublebufferlistview1=NewDoublebufferlistview (); // //DoubleBufferListView1// This. Doublebufferlistview1.font =NewSystem.Drawing.Font ("Microsoft Ya-Black",10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); This. Doublebufferlistview1.fullrowselect =true; This. doublebufferlistview1.hideselection =false; This. doublebufferlistview1.location =NewSystem.Drawing.Point ( -,Panax Notoginseng); This. Doublebufferlistview1.name ="DoubleBufferListView1"; This. doublebufferlistview1.size =NewSystem.Drawing.Size ( -,191); This. Doublebufferlistview1.tabindex =2; This. Doublebufferlistview1.usecompatiblestateimagebehavior =false; This. Doublebufferlistview1.view = System.Windows.Forms.View.Details;
2. Add it to form
this. Controls.Add (this. doubleBufferListView1);
3. To add a column
doublebufferlistview1.clear (); DOUBLEBUFFERLISTVIEW1.COLUMNS.ADD ("Action", the, System.Windows.Forms.HorizontalAlignment.Left); DOUBLEBUFFERLISTVIEW1.COLUMNS.ADD ("value", the, System.Windows.Forms.HorizontalAlignment.Right); DOUBLEBUFFERLISTVIEW1.COLUMNS.ADD ("Action", the, System.Windows.Forms.HorizontalAlignment.Left); DOUBLEBUFFERLISTVIEW1.COLUMNS.ADD ("value", the, System.Windows.Forms.HorizontalAlignment.Left);
4. Add a little bit of content
string[] Listviewdata =New string[4]; listviewdata[0] ="Action"; listviewdata[1] ="1"; listviewdata[2] ="Action"; listviewdata[3] ="1"; ListViewItem Lvitem=NewListViewItem (Listviewdata,0); DOUBLEBUFFERVIEW1.ITEMS.ADD (Lvitem);
5. Click the button to start running
Private voidButton1_Click (Objectsender, EventArgs e) {Thread th=NewThread (PlayGame); if(state = =false) { state=true; Button1. Text="Stop"; Th. IsBackground=true; Th. Name="New Thread"; Th. Start (); } Else{ state=false; Button1. Text="Start"; } } Private voidPlayGame () {Random R=NewRandom (); while(state) {stringtemp = R.next (0,Ten). ToString (); Label1. Text=temp; This. doublebufferlistview1.items[0]. subitems[1]. Text =temp; } }
6. Run the comparison chart:
On the left is the ListView effect that comes with the right side after resolving the splash screen
7. Run the program download:
Application download
C # Flashing resolution for updating data with ListView