C # ListView Subitem ask this value text change the interface will blink

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.