台脚
解决ListCtrl控件第⼀列⽂字不能居中显⽰的问题 把CListCtrl设置为Report风格,但是插⼊第⼀列的时候(InsertColumn)的时候会发现⽂字不能居中。即使使⽤了LVCFMT_CENTER,其他列都可以正常居中,但第⼀列仍然靠左显⽰。 解决⽅案:
(1)巧妙解决:插⼊第⼀列时宽度设置为0,弃之不⽤。但是这样有问题,凡是与第⼀列相关的⼀些设置将发挥不了作⽤,例如checkbox 和icon。 汽油机助力自行车(2)插⼊第⼀列后,改变它的参数:(我使⽤了这种⽅法)
LVCOLUMN lvc;
永磁电机设计lvc.mask = LVCF_FMT;
GetColumn(0, &lvc);
lvc.fmt &=~ LVCFMT_JUSTIFYMASK;
lvc.fmt |= LVCFMT_CENTER;
SetColumn(0, &lvc);
(3)插⼊第⼀列后,将其删除,第⼆列此时会充当第⼀列。
补充(csdn⽹友:VisualEleven):
MS⾃⼰搞的,第⼀列式不能设置格式的,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=0; i<sizeof(str)/sizeof(str[0]); i++)
{
m_list.InsertColumn(i, str[i], LVCFMT_CENTER, 100);
回铃音m_list.InsertItem(i, _T(""));
m_list.SetItemText(i, 0, _T("AAA"));
pvc绝缘材料
}
m_list.DeleteColumn(0);电子发声挂图