解决方法 就是重写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. linux中man 2与man 3区别

    1.Standard commands (标准命令)2.System calls (系统调用)3.Library functions (库函数)4.Special devices (设备说明)5.Fi ...

  2. 解决SurfaceView调用setZOrderOnTop(true)遮挡其他控件

    解决SurfaceView调用setZOrderOnTop(true)遮挡其他控件的问题 http://marller.blog.51cto.com/8699646/1762028 FAQ: Surf ...

  3. Android 资源目录 相关知识 raw、 drawable、 values..

    一定要看的 Android 资源目录的相关知识 raw drwable valueshttp://blog.csdn.net/shichexixi/article/details/5985677 ht ...

  4. pg数据库杀掉连接

    遇到异常连接时,需要将对应连接杀掉,可能是连接占用了过多CPU或是IO,影响了业务,或是时间过长的空闲事务. pg对于杀掉连接提供了专门的命令,一般情况下使用pg_cancel_backend就可以, ...

  5. android studio 代码混淆如何忽略第三方jar包

    日前在打包混淆包含第三方jar包的Android studio项目时 报出了各种错误,但是debug版本却能正常运行,于是怀疑android studio 打包的时候把第三方jar包给混淆了,第三方j ...

  6. (三)论sizeof与strlen之间的区别

    一.sizeof    sizeof(...)是运算符,在头文件中typedef为unsigned int,其值在编译时即计算好了,参数可以是数组.指针.类型.对象.函数等.    它的功能是:获得保 ...

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

    WHY C++ ? C++

  8. Python 装饰器(进阶篇)

    装饰器是什么呢? 我们先来打一个比方,我写了一个python的插件,提供给用户使用,但是在使用的过程中我添加了一些功能,可是又不希望用户改变调用的方式,那么该怎么办呢? 这个时候就用到了装饰器.装饰器 ...

  9. GoWeb_01:GoWeb基础之mac上mysql安装

    Mac下的MySql安装与配置 1. 访问MySQL的官网 http://www.mysql.com/downloads/ 然后在页面中会看到“MySQL Community Server”下方有一个 ...

  10. Hadoop基础原理

    Hadoop基础原理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 业内有这么一句话说:云计算可能改变了整个传统IT产业的基础架构,而大数据处理,尤其像Hadoop组件这样的技术出 ...