解决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 ...
随机推荐
- Windows系统时间同步出错解决办法(w32tm /register按回车,可能是为了解决时间COM注册的问题)
有时候我们设置本地时间与Internet时间同步时,经常连接服务器time.windows.com超时,导致时间同步失败,解决办法如下: 利用快捷键"Win+R"调出运行框,输入: ...
- Android CardView卡片布局 标签: 控件
CardView介绍 CardView是Android 5.0系统引入的控件,相当于FragmentLayout布局控件然后添加圆角及阴影的效果:CardView被包装为一种布局,并且经常在ListV ...
- springMVC No mapping found for HTTP request with URI
转载自:http://blog.sina.com.cn/s/blog_534f69a00101332u.html 1.问题: No mapping found for HTTP request wit ...
- kali之获取靶机的图片和看的url
需要用到 fping工具 用-asg参数 调查选项: -4,ipv4只能ping ipv4地址 -6——ipv6只在ping ipv6地址 -b——大小=字节数量的ping数据以字节的方式发送(默认为 ...
- SimpleDateFormat 时间格式化
- 【Codeforces Round #460 (Div. 2) C】 Seat Arrangements
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用pre[i][j]表示第i行前j列的和. 然后枚举连续座位的最左上点. (有两种可能向右或向下k个. 则还需要处理出pre2[i] ...
- Java 位运算符 深入理解
在Java中存在着这样一类操作符,是针对二进制进行操作的.它们各自是&.|.^.~.>>.<<.>>>几个位操作符.不管是初始值是依照何种进制,都会换 ...
- Android Studio升级到0.8.1后怎样设置字体大小?
升级到0.8.1后.打开设置字体大小页面.你会发现无论是Default还是Darcula,都不同意你改变字体的大小.事实上这个是由于这两个模式是Android Studio自带模式,所以不同意你修改, ...
- 设置eclipse中的字体大小
- es65 跨模块常量
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...