[MFC] List Control第一列为什么无法居中?

事实是微软规定第一列式不能设置格式,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的列作为保留,插完所有列后删除第0列,此后对表格的访问索引依然会从0开始,即使一开始没有对此进行处理,也不需要修改后面的处理代码。

m_list_objclasses.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
m_list_objclasses.InsertColumn(0,"保留",LVCFMT_CENTER);
m_list_objclasses.InsertColumn(1,"类名",LVCFMT_CENTER);
m_list_objclasses.InsertColumn(2,"库名",LVCFMT_CENTER);
m_list_objclasses.InsertColumn(3,"属性",LVCFMT_CENTER);
m_list_objclasses.InsertColumn(4,"实例",LVCFMT_CENTER);
m_list_objclasses.DeleteColumn(0);<span style="white-space:pre">	</span>//删除第0列
m_list_objclasses.SetColumnWidth(0,100);//依然从0开始访问
m_list_objclasses.SetColumnWidth(1,110);
m_list_objclasses.SetColumnWidth(2,70);
m_list_objclasses.SetColumnWidth(3,143);
效果如下:



参考:http://bbs.csdn.net/topics/330257954

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值