当我使用了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. Linux下的搜索查找命令的详解(which)

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

  2. @media 媒体查询

    @media screen and (max-width: 300px) { //当视口宽度小于等于300px时生效 } max-width  相当于  <=  @media screen an ...

  3. python 接口自动化测试(六)使用unittest 批量用例管理

    我们日常项目中的接口测试案例肯定不止一个,当案例越来越多时我们如何管理这些批量案例?如何保证案例不重复?如果案例非常多(成百上千,甚至更多)时如何保证案例执行的效率?如何做(批量)测试数据的管理?如何 ...

  4. Spring-boot(二)--thymeleaf

    @Controller @RequestMapping("/") public class MessageController { private final MessageRep ...

  5. mac 初次配置apache,及mac下安装mysql

    先打开apache,在浏览器上输入  localhost     回车后会如果屏幕上显示:It works! 如下图: 这说明你的apache已开启 mac 下apache配置(mac自带apache ...

  6. 查看 java 中的编译的字节码文件

    javap -c Atomicity ---------- javap -c 产生的字节码文件---------- Compiled from "Atomicity.java" p ...

  7. 【C++类与对象】实验四(二)

    实现画图类 #ifndef GRAPH_H #define GRAPH_H // 类Graph的声明 class Graph { public: Graph(char ch, int n); // 带 ...

  8. js设计模式(五)---观察者模式

    概述: 观察者模式也叫 “ 发布-订阅 " 模式 , 发布者发布信息是不需要考虑订阅者是谁?添加订阅者的时候也不需要通知发布者. 应用: 最经典的就是: DOM事件 开发过程中我们常用自定义 ...

  9. maven学习之pom.xml或settings.xml对nexus的配置(转)

    (1)在POM中配置Nexus仓库 <project>         ...         <repositories>            <repository ...

  10. python语法_if判断

    age_of_princal = 56 guess_age = int(input("e guess a age:")) if guess_age == age_of_princa ...