使用OwnerDraw改变ListView的ColumnHeader
当我使用了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的更多相关文章
- android 动态改变listview的内容
本文模拟:点击一个按钮,为已有的listview添加一行数据 <?xml version="1.0" encoding="utf-8"?> < ...
- Android中Selector的用法(改变ListView和Button的默认背景)
Android中的Selector的用法 http://blog.csdn.net/shakespeare001/article/details/7788400#comments Android中的S ...
- 【Android多屏适配】动态改变Listview item高度
在ListView的Adapter中去直接获取传入View的LayoutParams是会报空指针异常的,唯一的方法是在xml中嵌套布局一层LinearLayout <?xml version=& ...
- 改变listview中item选中时文字的颜色
摘要 当listview的某个item选中时,默认有个选中的高亮显示,如果你要自定义选中时的高亮显示效果,可以在listview中设置属性 android:listSelector="@dr ...
- winform ListView创建columnHeader的方法
using System; using System.Windows.Forms; using System.Drawing; using System.Collections; namespace ...
- Android仿支付宝扣款顺序,动态改变ListView各Item次序
前言:今天遇到个需求,需要让用户动态选择语音传输方式的次序,突然想起支付宝选择扣款顺序的功能,恰好能满足需要,就花了点时间写了个demo,在此权当学习记录 先上效果图 支付宝的效果 demo的效果 思 ...
- Android中动态改变Listview中字体的颜色
效果如下: 账目显示用的是Listview,要实现的功能为使其根据所在Item是“收入”还是“支出”来把数字设置成绿色或红色 方法是自定义适配器,并重写其中getView()函数,实现如下: //自定 ...
- 动态改变Listview的item背景颜色和item中字体的颜色
https://blog.csdn.net/qq_14813933/article/details/50417859
- 如何改变 FMX ListView 颜色
需求:改变 ListView 颜色 适用:Firemonkey 任何平台 操作:Style 是改变控件外观最便捷的途径,ListView 也不例外,下面示范使用 StyleBook 来设定 ListV ...
随机推荐
- PHP中通过bypass disable functions执行系统命令的几种方式
原文:http://www.freebuf.com/articles/web/169156.html 一.为什么要bypass disable functions 为了安全起见,很多运维人员会禁用PH ...
- PHP(控制语句,随机数,循环语法)
1.随机数:Math.random():0到1 不包括1 永远取不到2.控制语句if(){} for循环 语法 运行步骤(过程,原理) 1.初始化 2.判断条件 3.变量改变 index:下 ...
- html的基本语法
- javascript数组的实例属性(方法)
javascript的所有数组实例对象,除了可以给自己增删属性之外:都会从Array.prototype继承属性(方法).修改Array的原型会影响所有的数组实例. 数组实例的属性: Array.pr ...
- CentOS7.6 安装Docker
删除已安装的Docker # Uninstall installed docker sudo yum remove docker \ docker-client \ docker-client-lat ...
- linux c生成唯一文件名称
linux c生成唯一文件名称可用mktemp()或mkstemp()函数
- 洛谷P2569 股票交易 [SCOI2010] dp
正解:dp+单调队列优化 解题报告: 先放个传送门鸭qwq umm首先dp转移挺好想的?就买和不买 f[i][j]表示第i天手上有j的股份的最多钱,转移也很好想?就枚举第1天到第i-w-1天枚举买k股 ...
- angular--获取时间方法services
写了一些公用方法获取自然周.传入开始和结束日期,获取中间全部日期等方法 .service('DateServices', [function () { // 获取某年自然周的方法 (如果是当年,只返回 ...
- luogu2839 [国家集训队]middle
题目链接:洛谷 题目大意:给定一个长度为$n$的序列,每次询问左端点在$[a,b]$,右端点在$[c,d]$的所有子区间的中位数的最大值.(强制在线) 这里的中位数定义为,对于一个长度为$n$的序列排 ...
- 数据类型&字符串得索引及切片
一:数据类型 1):int 1,2,3用于计算 2):bool ture false 用于判断,也可做为if的条件 3):str 用引号引起来的都是str 存储少量数据,进行 ...