解决方法 就是重写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. 使用IPMI控制/监控Linux服务器

    1       IPMI简述 IPMI提供了很多丰富功能,我使用的功能,说得大白话一点,就是: 1.获取本设备的硬件信息:包括CPU和主板的温度.电压.风扇转速. 2.在设备A上,通过命令,控制远程设 ...

  2. 小技巧--tab键自动补齐Git命令

    Git是什么,你不清楚? 好吧,那么该篇内容对你也木有帮助,请绕道而行.. 我们在使用Git命令时,可以通过tab键,自动补齐Git,特别是在切换分支时特别有用. 如下,当我们想将当前分支切换到bug ...

  3. WHY C++ ?(by Herb Sutter) & C++17 standard

    WHY C++ ? C++

  4. 百度语音合成 composer

    https://packagist.org/packages/jormin/baidu-speech http://ai.baidu.com/docs#/TTS-Online-PHP-SDK/top

  5. vue学习记录

    vue中常用的指令 v-model 双向数据绑定,一般用于表单元素 v-for 对数组或对象进行循环操作,使用的是v-for <!-- 普通循环 --><li v-for=" ...

  6. vs配置SP++3.0

    最近在研究信号处理的C语言算法,突然发现一个西安交大的师兄之前已经写出来了一个完整的库,同样是研究生三年,差别怎么这样大呢. 先从用轮子开始吧. 一.SP++3.0安装及测试 官网下载地址: http ...

  7. bzoj千题计划115:bzoj1024: [SCOI2009]生日快乐

    http://www.lydsy.com/JudgeOnline/problem.php?id=1024 枚举横着切还是竖着切,一边儿分多少块 #include<cstdio> #incl ...

  8. 贪心问题:区间覆盖 POJ 2376 Cleaning Shift

    题目:http://poj.org/problem?id=2376 题意:就是 N 个区间, 输入 N 个区间的 [begin, end],求能用它们覆盖区间[1,T]的最小组合. 题解: 1. 首先 ...

  9. ETL测试

    今天让我在休息之余给我的测试朋友介绍一个在我的测试沙龙上的需要和提升技能之一,例如ETL测试(Extract,Transform,and Load,中文名称为数据提取.转换和加载),这篇文章告诉你ET ...

  10. nc使用笔记

    netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它. 现内网中有两台机器:Mac: 192.168.1.109 Ka ...