解决方法 就是重写ListView,然后设置双缓冲即可,然后再使用DoubleBufferListView,就不会闪烁了。下面的代码是DoubleBufferListView,并使用FrmMain来测试效果。

代码如下

第一步:DoubleBufferListView

public class DoubleBufferListView : ListView
{
public DoubleBufferListView()
{
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
UpdateStyles();
}
}

第二步

新建测试窗体FrmMain ,并使用DoubleBufferListView

public FrmMain()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
ListView doubleBufferListView1 = new ListView();
//
// doubleBufferListView1
//
doubleBufferListView1.Font = new System.Drawing.Font("微软雅黑", 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", 80, System.Windows.Forms.HorizontalAlignment.Left);
doubleBufferListView1.Columns.Add("value", 80, System.Windows.Forms.HorizontalAlignment.Right);
doubleBufferListView1.Columns.Add("Action", 80, System.Windows.Forms.HorizontalAlignment.Left);
doubleBufferListView1.Columns.Add("value", 80, 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);
}

第三步:按钮事件

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 = "停止";

th.Name = "新线程";
th.Start();
}
else
{
state = false;
button1.Text = "开始";

}
}
private void PlayGame()
{
//try
//{
Random r = new Random();
while (state)
{
if (IsHandleCreated)
{

//Invoke跨线程调用,MethodInvoker  这个内部分委托,非常方便。亲测,其他委托关闭主窗体时会报错。
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 问本值 text 改变 界面会闪烁的更多相关文章

  1. js/jquery获取文本框的值与改变文本框的值

    我们就用它来学习获取文本框的值及改变文本框的值. 代码如下 复制代码 <script>function get1(){ document.getElementById("txtb ...

  2. jQuery改变label/input的值,改变class,改变img的src

    jQuery改变label/input的值.改变class,改变img的src jQuery改变label的值: $('#aID').text("New Value"); jQue ...

  3. Bean熟悉替换,只替换部分属性,其他属性值不改变

    Bean熟悉替换,只替换部分属性,其他属性值不改变 需要加入:asm.jar  cglib-2.1.jar,用来map和bean之间的转换(比spring和反射的效率好,因为加入了缓存) packag ...

  4. 小程序中监听textarea或者input输入的值动态改变data中数组的对象的值

    Page({ data: { todoLists:[ { detail:"", date:"", location:"", priority ...

  5. 数组和String调用方法时,值是否改变(包含可变参数)

    package com.wh.encapsulation; import java.util.Arrays; /** * @author 王恒 * @datetime 2017年4月5日 上午9:33 ...

  6. WPF 获取 ListView DataTemplate 中控件值

    原文:WPF 获取 ListView DataTemplate 中控件值 版权声明:本文为博主原创文章,未经博主允许可以随意转载 https://blog.csdn.net/songqingwei19 ...

  7. WPF动画之后属性值无法改变

    原文:WPF动画之后属性值无法改变         前一段时间使用WPF写2048游戏的时候,遇到下面的情形:使用按键对色块进行移动时,触发位置左边X和Y属性的DoubleAnimation动画,但是 ...

  8. Android中ListView异步加载图片错位、重复、闪烁问题分析及解决方案

    我们在使用ListView异步加载图片的时候,在快速滑动或者网络不好的情况下,会出现图片错位.重复.闪烁等问题,其实这些问题总结起来就是一个问题,我们需要对这些问题进行ListView的优化. 比如L ...

  9. Ajax编程中,经常要能动态的改变界面元素的样式

    在Ajax编程中,经常要能动态的改变界面元素的样式,可以通过对象的style属性来改变,比如要改变背景色为红色,可以这样写:element.style.backgroundColor=”#ff0000 ...

随机推荐

  1. SpringBoot 中使用redis以及redisTemplate

    1.首先在pom.xml中添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <art ...

  2. 牛客网NOIP赛前集训营-普及组(第一场)

    前三题略 T4: 题目描述 小A有n个长度都是L的字符串.这些字符串只包含前8个小写字符,'a'~'h'.但这些字符串非常的混乱,它们几乎长得互不相同.小A想通过一些规则,让它们长得尽可能相同.小A现 ...

  3. GeoDa计算全局Moran‘I

    GeoDa计算全局Moran‘I 1.导入包含数据的.shp文件 2.创建权重矩阵,点击Weight Manger,再点击Create, weights file ID variable(其中包含的数 ...

  4. CODEVS 2171 棋盘覆盖

    2171 棋盘覆盖 给出一张nn(n<=100)的国际象棋棋盘,其中被删除了一些点,问可以使用多少12的多米诺骨牌进行掩盖. 错误日志: 直接在模板上调整 \(maxn\) 时没有在相应邻接表数 ...

  5. supervisor自启动

    supervisor自启动 其实自启动,也就是在主机开启的时候,执行了sudo supervisord -c /etc/supervisord.conf: 创建/usr/lib/systemd/sys ...

  6. tomcat 性能检测

    一.jconsole 1.tomcat在windows上,start方式启动 在catalina.bat 文件中的:doRun和:doStart下添加以下代码 (没有换行) set JAVA_OPTS ...

  7. nginx配置详情(总结)

    Nginx简介 Nginx是一款开源代码的高性能HTTP服务器和反向代理服务器,同时支持IMAP/POP3/SMTP代理服务 Nginx工作原理 Nginx由内核和模块组成,完成工作是通过查找配置文件 ...

  8. poj 3216 Repairing Company

    http://poj.org/problem?id=3216 n个地点,m个任务 每个任务有工作地点,开始时间,持续时间 最少派多少人可以完成所有的任务 传递闭包之后最小路径覆盖 #include&l ...

  9. codevs 2147 数星星

    2147 数星星 http://codevs.cn/problem/2147/ 题目描述 Description 小明是一名天文爱好者,他喜欢晚上看星星.这天,他从淘宝上买下来了一个高级望远镜.他十分 ...

  10. jenkins 相关默认信息

    (1) 默认安装目录    /usr/lib/jenkins/:jenkins安装目录,WAR包会放在这里.  ( 2 )  默认配置文件 /etc/sysconfig/jenkins:jenkins ...