当我使用了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. Elasticsearch学习之有用博客

    推荐阅读:1.阿里:https://elasticsearch.cn/article/61712.滴滴:http://t.cn/EUNLkNU3.腾讯:http://t.cn/E4y9ylL4.携程: ...

  2. Linux下的搜索查找命令的详解(which)

    我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索:  which  查看可执行文件的位置. whereis 查看文件的位置.  locate   配合数据库查看文件 ...

  3. JavaScript 里,$ 代表什么?/JQuery是什么语言?/html中用link标签引入css时的中 rel="stylesheet"属性?/EL表达式是什么?

    JavaScript 里,$ 代表什么? 比如说我写一个mouseover事件: $(document).ready(function(){ $("p").mouseover(fu ...

  4. Linux上传文件与执行

    ls ——查看文件夹 mkdir——新建文件夹 cd:——进入文件 nohup python3 文件名.py & ——让代码在后台运行 ps -aux | grep 文件——查看进程 ps-a ...

  5. django cookies与session

    1. cookiies # cookies def login(request): print('COOKIES',request.COOKIES) print('SESSION',request.s ...

  6. C#常用加密方法

    using System; using System.IO; using System.Security.Cryptography; using System.Text; /// <summar ...

  7. python基础,if语句,while循环

    if语句: ①2选一                                              ④多选一 if:     条件                              ...

  8. Codeforces 1089E - Easy Chess - [DFS+特判][2018-2019 ICPC, NEERC, Northern Eurasia Finals Problem E]

    题目链接:https://codeforces.com/contest/1089/problem/E Elma is learning chess figures. She learned that ...

  9. Golang数据类型总结及其转换

    golang数据类型 基本类型:boolean,numeric,string类型的命名实例是预先声明的. 复合类型:array,struct,指针,function,interface,slice,m ...

  10. Intro to Mongoid

    Mongoid: object-document-mapper(ODM) Mongoid Configuration: rails g mongoid:config Document: Documen ...