当我使用了OwnerDraw改变ListView的ColumnHeader的颜色之后,发现行无法显示内容了.其原因就是OwnerDraw属性设置为True造成了,也就是说,这个属性需要我们重画ListView中的各种内容,我们先是使用DrawColumnHeader消息重画了ColumnHeader,使其改变了颜色,但没有重画Item和SubItem,也就是行,因此行中的数据无法显示了,所以我们还要使用DrawItem和DrawSubItem两个消息生成函数.

listViewNoFlickerWei.OwnerDraw = true;
listViewNoFlickerWei.DrawColumnHeader += new DrawListViewColumnHeaderEventHandler(listViewNoFlickerWei_DrawColumnHeader);
listViewNoFlickerWei.DrawItem += new DrawListViewItemEventHandler(listViewNoFlickerWei_DrawItem);
listViewNoFlickerWei.DrawSubItem += new DrawListViewSubItemEventHandler(listViewNoFlickerWei_DrawSubItem);

void listViewNoFlickerWei_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
using (StringFormat sf = new StringFormat())
{
// Store the column text alignment, letting it default
// to Left if it has not been set to Center or Right.
switch (e.Header.TextAlign)
{
case HorizontalAlignment.Center:
sf.Alignment = StringAlignment.Center;
break;
case HorizontalAlignment.Right:
sf.Alignment = StringAlignment.Far;
break;
} // Draw the standard header background.
e.DrawBackground(); // Draw the header text.
using (Font headerFont =
new Font("Helvetica", , FontStyle.Bold))
{
e.Graphics.DrawString(e.Header.Text, headerFont,
Brushes.Black, e.Bounds, sf);
}
}
return;
}
void listViewNoFlickerWei_DrawItem(object sender, DrawListViewItemEventArgs e)
{
if ((e.State & ListViewItemStates.Selected) != )
{
// Draw the background and focus rectangle for a selected item.
e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds);
e.DrawFocusRectangle();
}
else
{
Point tPoint = new Point();
SolidBrush tFrontBrush = new SolidBrush(Color.Black);
Font tFont = new Font("宋体", , FontStyle.Regular);
tPoint.X = e.Bounds.X + ;
tPoint.Y = e.Bounds.Y + ;
e.Graphics.DrawString(e.Item.Text, tFont, tFrontBrush, tPoint);
}
}
void listViewNoFlickerWei_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
Point tPoint = new Point();
SolidBrush tFrontBrush = new SolidBrush(Color.White);
Font tFont = new Font("宋体", , FontStyle.Regular);
tPoint.X = e.Bounds.X + ;
tPoint.Y = e.Bounds.Y + ;
e.Graphics.DrawString(e.SubItem.Text, tFont, tFrontBrush, tPoint);
}

使用OwnerDraw改变ListView的ColumnHeader的更多相关文章

  1. android 动态改变listview的内容

    本文模拟:点击一个按钮,为已有的listview添加一行数据 <?xml version="1.0" encoding="utf-8"?> < ...

  2. Android中Selector的用法(改变ListView和Button的默认背景)

    Android中的Selector的用法 http://blog.csdn.net/shakespeare001/article/details/7788400#comments Android中的S ...

  3. 【Android多屏适配】动态改变Listview item高度

    在ListView的Adapter中去直接获取传入View的LayoutParams是会报空指针异常的,唯一的方法是在xml中嵌套布局一层LinearLayout <?xml version=& ...

  4. 改变listview中item选中时文字的颜色

    摘要 当listview的某个item选中时,默认有个选中的高亮显示,如果你要自定义选中时的高亮显示效果,可以在listview中设置属性 android:listSelector="@dr ...

  5. winform ListView创建columnHeader的方法

    using System; using System.Windows.Forms; using System.Drawing; using System.Collections; namespace ...

  6. Android仿支付宝扣款顺序,动态改变ListView各Item次序

    前言:今天遇到个需求,需要让用户动态选择语音传输方式的次序,突然想起支付宝选择扣款顺序的功能,恰好能满足需要,就花了点时间写了个demo,在此权当学习记录 先上效果图 支付宝的效果 demo的效果 思 ...

  7. Android中动态改变Listview中字体的颜色

    效果如下: 账目显示用的是Listview,要实现的功能为使其根据所在Item是“收入”还是“支出”来把数字设置成绿色或红色 方法是自定义适配器,并重写其中getView()函数,实现如下: //自定 ...

  8. 动态改变Listview的item背景颜色和item中字体的颜色

    https://blog.csdn.net/qq_14813933/article/details/50417859

  9. 如何改变 FMX ListView 颜色

    需求:改变 ListView 颜色 适用:Firemonkey 任何平台 操作:Style 是改变控件外观最便捷的途径,ListView 也不例外,下面示范使用 StyleBook 来设定 ListV ...

随机推荐

  1. 深入理解 Java 虚拟机之学习笔记(3)

    垃圾回收(Garbage Collection,GC ),GC的历史其实比Java久远,1960年诞生与MIT的Lisp是第一门真正使用内存动态分配和垃圾收集技术的语言.当Lisp还在胚胎时期时,人们 ...

  2. 以太坊: ETH 发送交易 sendRawTransaction 方法数据的签名 和 验证过程

    作者:林冠宏 / 指尖下的幽灵 掘金:https://juejin.im/user/587f0dfe128fe100570ce2d8 博客:http://www.cnblogs.com/linguan ...

  3. Centos下普通用户设置sudo权限

    若执行sudo命令的用户没有sodu权限,则会报以下错误 violet is not in the sudoers file.This incident will be reported 若想让vio ...

  4. 【1】public

    [面向对象] 李坤是不是人?(人类) 飞飞是不是人?(人类) 扎心是不是人?(人类) 是:特指某一个事物 属于:同一的类型 什么是对象: 就是特指的某一个东西,万物皆对象 什么是类: 具有一批相同属性 ...

  5. 28、gulp

    一.gulp的作用? 1.gulp-sass : 编译sass 2.gulp-rename : 重命名 3.gulp-cssnano : 压缩css 4.gulp-concat : 合并文件 5.gu ...

  6. Spring-Boot自动装载servlet

    Spring-Boot自动装载servlet 本人spring-boot相关博客均自己手动编写,但技术均从简书 恒宇少年 处学习,该大佬一直是我的偶像,鉴于能充分理解,所以已做笔记的方式留下这些文档, ...

  7. php 判断手机号 和 手机号中间四位以**** 代替

    代码: //自定义函数手机号隐藏中间四位 function get_phone($str){ $str=$str; $resstr=substr_replace($str,'****',3,4); r ...

  8. Tunnels HDU - 4856

    BFS寻找每个点到其他点的最小距离 再状压DP,DP[i][j] i二进制表示每个点的到达状态,j为当前所在点 #include<iostream> #include<cstring ...

  9. ES6 数组方法拓展

    ES6 数组方法拓展 1.Array.from() Array.from方法用于将两类对象转为真正的数组:类似数组的对象(array-like object)和可遍历(iterable)的对象(包括E ...

  10. [bash][awk] bash下使用awk方便的列求和

    这么多年,始终在用awk进行文本处理.但是一直没有好好的学习awk的语法.所以很多情况都是知其然,不知其所以然. 如今,亦如此.先记下来如下,以后有时间系统的学习一下awk的语法. ┬─[tong@T ...