The workaround is to rewrite the ListView and then set the double buffer and then use the Doublebufferlistview to not blink. The following code is Doublebufferlistview and uses frmmain to test the effect.
The code is as follows
First step: Doublebufferlistview
public class Doublebufferlistview:listview
{
Public Doublebufferlistview ()
{
SetStyle (Controlstyles.doublebuffer | Controlstyles.optimizeddoublebuffer | Controlstyles.allpaintinginwmpaint, True);
UpdateStyles ();
}
}
Step Two
Create a new test form frmmain, and use the Doublebufferlistview
Public Frmmain ()
{
InitializeComponent ();
Checkforillegalcrossthreadcalls = false;
ListView DoubleBufferListView1 = new ListView ();
//
DoubleBufferListView1
//
Doublebufferlistview1.font = new System.Drawing.Font ("Microsoft Jas Black", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (134)));
Doublebufferlistview1.fullrowselect = true;
Doublebufferlistview1.hideselection = false;
Doublebufferlistview1.location = new System.Drawing.Point (50, 37);
Doublebufferlistview1.name = "DoubleBufferListView1";
Doublebufferlistview1.size = new System.Drawing.Size (400, 191);
Doublebufferlistview1.tabindex = 2;
Doublebufferlistview1.usecompatiblestateimagebehavior = false;
Doublebufferlistview1.view = System.Windows.Forms.View.Details;
THIS.PNLFLASHING.CONTROLS.ADD (DOUBLEBUFFERLISTVIEW1);
Doublebufferlistview1.clear ();
DOUBLEBUFFERLISTVIEW1.COLUMNS.ADD ("Action", System.Windows.Forms.HorizontalAlignment.Left);
DOUBLEBUFFERLISTVIEW1.COLUMNS.ADD ("value", System.Windows.Forms.HorizontalAlignment.Right);
DOUBLEBUFFERLISTVIEW1.COLUMNS.ADD ("Action", System.Windows.Forms.HorizontalAlignment.Left);
DOUBLEBUFFERLISTVIEW1.COLUMNS.ADD ("value", System.Windows.Forms.HorizontalAlignment.Left);
string[] Listviewdata = new String[4];
Listviewdata[0] = "Action";
LISTVIEWDATA[1] = "1";
LISTVIEWDATA[2] = "Action";
LISTVIEWDATA[3] = "1";
ListViewItem Lvitem = new ListViewItem (listviewdata, 0);
DOUBLEBUFFERLISTVIEW1.ITEMS.ADD (Lvitem);
}
Step Three: Button events
BOOL State;
private void Button1_click_1 (object sender, EventArgs e)
{
Thread th = new Thread (PlayGame);
Th. IsBackground = true;
if (state = = False)
{
state = true;
Button1. Text = "Stop";
Th. Name = "New Thread";
Th. Start ();
}
Else
{
state = false;
Button1. Text = "Start";
}
}
private void PlayGame ()
{
Try
//{
Random r = new Random ();
while (state)
{
if (ishandlecreated)
{
Invoke cross-thread invocation,methodinvoker This inner part of the delegate, very convenient. The other delegate closes the main form with an error.
This. Invoke ((MethodInvoker) delegate ()
{
String temp = R.next (0, 10). ToString ();
Label1. Text = temp;
(ListView) pnlflashing. controls["DoubleBufferListView1"]). Items[0]. SUBITEMS[1]. Text = temp;
Application.doevents ();
});
}
if (this. ishandlecreated)
//{
String temp = R.next (0, 10). ToString ();
Label1. Text = temp;
This. Invoke (new methodinvoker () =
// {
Label1. Text = temp;
(ListView) pnlflashing. controls["DoubleBufferListView1"]). Items[0]. SUBITEMS[1]. Text = temp;
// }));
//}
}
//}
Catch
//{
//}
}
}
C # ListView Subitem ask this value text change the interface will blink