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

来源:互联网 发布:怎么能提高淘宝销量 编辑:程序博客网 时间:2024/05/16 09:22

事实是微软规定第一列式不能设置格式,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

0 0
原创粉丝点击