解决ListCtrl控件第一列文字不能居中显示的问题/修改网格线
把CListCtrl设置为Report风格,但是插入第一列的时候(InsertColumn)的时候会发现文字不能居中。即使使用了LVCFMT_CENTER,其他列都可以正常居中,但第一列仍然靠左显示。
插入第一列后,改变它的参数:
LVCOLUMN lvc;
lvc.mask = LVCF_FMT;
GetColumn(, &lvc);
lvc.fmt &=~ LVCFMT_JUSTIFYMASK;
lvc.fmt |= LVCFMT_CENTER;
SetColumn(, &lvc);
第一列式不能设置格式的,MSDN里有说明: If a column is added to a list-view control with index 0 (the leftmost column) and with LVCFMT_RIGHT or LVCFMT_CENTER specified, the text is not right-aligned or centered. The text in the index 0 column is left-aligned. Therefore if you keep inserting columns with index 0, the text in all columns are left-aligned. If you want the first column to be right-aligned or centered you can make a dummy column, then insert one or more columns with index 1 or higher and specify the alignment you require. Finally delete the dummy column.
大致意思是这样的:索引为0的列(最左边的列)如果设置了LVCFMT_RIGHT或LVCFMT_CENTER属性,上面的文字并不会右对齐或居中对齐。索引为0 的列是左对齐。如果你要想第一列右对齐或者居中对齐,你可以这样做,先保留索引为0的列,其他的列均指定右对齐或居中对齐属性,最后删除索引为0的列。
下面是实例代码:
m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
CString str[] ={_T(""), _T("AAA"), _T("BBB"), _T("CCC"), _T("DDDD"), _T("EEE")};
for(int i=; i<sizeof(str)/sizeof(str[]); i++)
{
m_list.InsertColumn(i, str[i], LVCFMT_CENTER, );
m_list.InsertItem(i, _T(""));
m_list.SetItemText(i, , _T("AAA"));
}
m_list.DeleteColumn();
修改网格线颜色:
const MSG *msg = GetCurrentMessage();
DefWindowProc(msg->message, msg->wParam, msg->lParam); //这两句不能省,否则程序会因消息循环出现异常 // Draw the lines only for LVS_REPORT mode
if ((GetStyle() & LVS_TYPEMASK) == LVS_REPORT)
{
// Get the number of columns
CClientDC dc(this);
CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem();
int nColumnCount = pHeader->GetItemCount(); // The bottom of the header corresponds to the top of the line
RECT rect;
pHeader->GetClientRect(&rect);
int top = rect.bottom; // Now get the client rect so we know the line length and
// when to stop
GetClientRect(&rect); // The border of the column is offset by the horz scroll
int borderx = - GetScrollPos(SB_HORZ); CPen listSepPen(PS_SOLID, , RGB(, , )); //定制你的分割线的颜色
CPen *pOldPen = dc.SelectObject(&listSepPen); for (int i = ; i < nColumnCount; i++)
{
// Get the next border
borderx += GetColumnWidth(i); // if next border is outside client area, break out
if (borderx >= rect.right) break; // Draw the line.
dc.MoveTo(borderx, top);
dc.LineTo(borderx, rect.bottom);
} // Draw the horizontal grid lines // First get the height
if (!GetItemRect(, &rect, LVIR_BOUNDS))
return; int height = rect.bottom - rect.top; GetClientRect(&rect);
int width = rect.right; for (int i = ; i <= GetCountPerPage(); i++)
{
dc.MoveTo(, top + height*i);
dc.LineTo(width, top + height*i);
} dc.SelectObject(pOldPen);
解决ListCtrl控件第一列文字不能居中显示的问题/修改网格线的更多相关文章
- delphi ,1)控件根据窗口大小,一直居中显示 2)显示最大化最小化按钮控件
一.控件根据窗口大小,一直居中显示 1)onResize:当窗体尺寸改变时发生 例子:如何使控件随窗口的放大和缩小动态改变自己的大小,使控件“保存.返回”在窗口变大变小中随着变. 在Panel调用 p ...
- VC/MFC ListCtrl 控件功能使用汇总(转)
以下未经说明,listctrl默认view 风格为report 相关类及处理函数 MFC:CListCtrl类 SDK:以 “ListView_”开头的一些宏.如 ListView_InsertCol ...
- LISTCTRL控件方法
以下未经说明,listctrl默认view风格为report --------------------------------------------------------------------- ...
- CSharpGL(26)在opengl中实现控件布局/渲染文字
CSharpGL(26)在opengl中实现控件布局/渲染文字 效果图 如图所示,可以将文字.坐标轴固定在窗口的一角. 下载 CSharpGL已在GitHub开源,欢迎对OpenGL有兴趣的同学加入( ...
- ListCtrl控件的使用
list contrl控件的使用 .建立基于对话框的应用程序,布置界面,设置属性. 注意添加的是listctrl控件,不是listbox控件,在控件工具箱的倒数第五行list control控件. 属 ...
- easyUI的datagrid控件日期列不能正确显示Json格式数据的解决方案
EasyUI是一套比较轻巧易用的Jquery控件,在使用过程中遇到一个问题,它的列表控件——datagrid, 在显示日期列的时候,由于后台返回给页面的数据是Json格式的,其中的日期字段,在后台是正 ...
- ListCtrl控件
一 CListCtrl类型 LVS_EDITLABELS LVS_OWNERDRAWFIXED LVS_REPORT LVS_SHOWSELALWAYS LVS_SINGLESEL LVS_SMALL ...
- GridView控件隐藏列
GridView隐藏列visible="false" 后你就无法取得这列的值了 下面是迄今为止最简洁的解决方法了. protected void GVList_RowDataBou ...
- WinForm给控件加入hint文字
本文代码主要是参考别人的,仅为个人记录,方面后续使用~ 效果图: 主要代码在一个Win32Utility类中,代码如下: public static class Win32Utility { [Dll ...
随机推荐
- 使用Hadoop ACL 控制訪问权限
使用Hadoop ACL 控制訪问权限 一.HDFS訪问控制 hdfs-site.xml设置启动acl <property> <name>dfs.permissions.en ...
- 洛谷T21776 子序列
题目描述 你有一个长度为 nn 的数列 \{a_n\}{an} ,这个数列由 0,10,1 组成,进行 mm 个的操作: 1~l~r1 l r :把数列区间 [l, r][l,r] 内的所有数取反. ...
- SVN仓库目录结构
SVN仓库目录结构Repository: trunktagsbranches trunk(主干|主线) branchs(分支) tags(标记) truck(主干|主线|主分支):是用来做主方向开发的 ...
- angular实现简单的pagination分页组件
不想使用第三方库,只想使用一个分页器,那么就简单的实现一个,效果如下: 1.使用方式: <custom-pagination *ngIf="enterpriseList.length& ...
- Yeslab 华为安全HCIE七门之-防火墙基础(12篇)
Yeslab 华为安全HCIE七门之-防火墙基础(12篇) Yeslab 全套华为安全HCIE七门之第二门防火墙基础(12篇),第一门课论坛很早就有了,可自行下载,后面的陆续分享给大家. 华为安全HC ...
- jQuery 判断是否包含在数组中 jQuery.inArray()
var arr = [ "mysql", "php", "css", "js" ]; $.inArray(" ...
- Nginx缩略图和Fastdfs整合以及image_filter配置,7点经验结论和5个参考资料
以下是7点经验结论和5个参考资料 1.Nginx单独配置缩略图与Nginx和Fastdfs模块整合,配置是不一样的. 非整合模式的配置,类似这样的: location ~* /(\d+)\.(jpg ...
- 树莓派开机运行Python脚本 控制LED灯闪烁
一.新建一个开机运行文件 在 /home/pi/.config 下创建一个文件夹,名称为 autostart,并在该文件夹下创建一个led.desktop文件(文件名以.desktop结尾) 编辑le ...
- Your Ruby version is 2.2.3, but your Gemfile specified 2.2.2
在文章 Ruby On Rails中REST API使用演示样例--基于云平台+云服务打造自己的在线翻译工具 中,从Bluemix上下载的初始Hello World演示样例代码在本地环境下运行调试时提 ...
- headset-监听有线耳机插拔
今天在做项目的时候,需要对耳机的插拔事件进行监听,所以就写了如下的一个小demo,对耳机监听事件进行验证.直接看代码 package com.example.alert; import android ...