C# listView subitem 问本值 text 改变 界面会闪烁
解决方法 就是重写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 改变 界面会闪烁的更多相关文章
- js/jquery获取文本框的值与改变文本框的值
我们就用它来学习获取文本框的值及改变文本框的值. 代码如下 复制代码 <script>function get1(){ document.getElementById("txtb ...
- jQuery改变label/input的值,改变class,改变img的src
jQuery改变label/input的值.改变class,改变img的src jQuery改变label的值: $('#aID').text("New Value"); jQue ...
- Bean熟悉替换,只替换部分属性,其他属性值不改变
Bean熟悉替换,只替换部分属性,其他属性值不改变 需要加入:asm.jar cglib-2.1.jar,用来map和bean之间的转换(比spring和反射的效率好,因为加入了缓存) packag ...
- 小程序中监听textarea或者input输入的值动态改变data中数组的对象的值
Page({ data: { todoLists:[ { detail:"", date:"", location:"", priority ...
- 数组和String调用方法时,值是否改变(包含可变参数)
package com.wh.encapsulation; import java.util.Arrays; /** * @author 王恒 * @datetime 2017年4月5日 上午9:33 ...
- WPF 获取 ListView DataTemplate 中控件值
原文:WPF 获取 ListView DataTemplate 中控件值 版权声明:本文为博主原创文章,未经博主允许可以随意转载 https://blog.csdn.net/songqingwei19 ...
- WPF动画之后属性值无法改变
原文:WPF动画之后属性值无法改变 前一段时间使用WPF写2048游戏的时候,遇到下面的情形:使用按键对色块进行移动时,触发位置左边X和Y属性的DoubleAnimation动画,但是 ...
- Android中ListView异步加载图片错位、重复、闪烁问题分析及解决方案
我们在使用ListView异步加载图片的时候,在快速滑动或者网络不好的情况下,会出现图片错位.重复.闪烁等问题,其实这些问题总结起来就是一个问题,我们需要对这些问题进行ListView的优化. 比如L ...
- Ajax编程中,经常要能动态的改变界面元素的样式
在Ajax编程中,经常要能动态的改变界面元素的样式,可以通过对象的style属性来改变,比如要改变背景色为红色,可以这样写:element.style.backgroundColor=”#ff0000 ...
随机推荐
- hdu 5852 :Intersection is not allowed! 行列式
有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,bk). ...
- bzoj 1539: [POI2005]Dwu-Double-row
假设一列交换表示为1,不换表示为0. 身高相同的两个人相当于给其中两列了一个限制条件,要么是两个必须相等,要么一个为零一个为一. 有了关系后我们就可以把每列当成一个点建边,边权为0表示必须相同,1为必 ...
- 简例s - Variables
1. Set Variable 定义:Returns the given values which can then be assigned to a variables. 示例1: ${a} ...
- k-Nearest Neighbor algorithm 思想
转载 KNN--K最邻近算法思想 KNN算法的决策过程 k-Nearest Neighbor algorithm 上图中,绿色圆要被决定赋予哪个类,是红色三角形还是蓝色四方形?如果K=3, ...
- bzoj 1193 贪心+bfs
1193: [HNOI2006]马步距离 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2015 Solved: 914[Submit][Statu ...
- radio 控制器function用法
delivery_show(); $('.delivery_btn').on('click',function(){ delivery_show(); }); function delivery_sh ...
- Centos6.6下安装nginx1.6.3
安装环境: [root@nginx ~]# cat /etc/redhat-release CentOS release 6.6 (Final) [root@nginx ~]# uname -r 2. ...
- shell实例浅谈之一产生随机数七种方法
一.问题 Shell下有时需要使用随机数,在此总结产生随机数的方法.计算机产生的的只是“伪随机数”,不会产生绝对的随机数(是一种理想随机数).伪随机数在大量重现时也并不一定保持唯一,但一个好的伪随机产 ...
- windows环境下批处理实现守护进程
这个脚本提供两种方式守护,一种是通过进程名,但对于进程名都是java.exe的java程序不适用,另一种是通过netstat查找应用程序所监听的端口是否正在被监听.这两种方式可以在脚本中通过两个冒号注 ...
- [洛谷P2444] [POI2000]病毒
洛谷题目链接:[POI2000]病毒 题目描述 二进制病毒审查委员会最近发现了如下的规律:某些确定的二进制串是病毒的代码.如果某段代码中不存在任何一段病毒代码,那么我们就称这段代码是安全的.现在委员会 ...