我在对话框程序中的一个CListCtrl第二列加入了图标,怎样才能使它们居中显示?
只加入文字就可以,假如图标就不行了。

解决方案 »

  1.   

    use customerdraw
    see http://blog.csdn.net/jiangsheng/archive/2003/11/20/3796.aspx and http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/listview/notifications/nm_customdraw_listview.asp
      

  2.   

    怎么LZ问了两贴 LVCOLUMN lv_column;
    memset(&lv_column,0,sizeof(LVCOLUMN));
    lv_column.mask = LVCF_TEXT | LVCF_FMT;
    m_list.SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
    for( int i=0 ; i<6 ; i++ )
    {
    lv_column.fmt = LVCFMT_CENTER;
    }
    这样可以了吧?
      

  3.   

    m_list.DeleteColumn(0);应该放在操作的最后
      

  4.   

    问题比较麻烦,我的目的是在listctrl中插入四列,第一列只有文本,居左显示。第二列显示图像,居中。
    现在有两个问题:
    1:SetImageList后,第一列自动加入了图像,用代码去掉图像后,原来显示图像的地方还留了一块空白,文字显示在这块空白的旁边。怎样去掉这块空白?
    2:第二列加入图像后,无法居中显示,实际为居左。
    不知我说明白了没有,这是我的代码:
    ListView_SetExtendedListViewStyle(m_list.m_hWnd, LVS_EX_SUBITEMIMAGES);

    m_list.InsertColumn(0,"1",LVCFMT_LEFT,80);
    m_list.InsertColumn(1,"2",LVCFMT_CENTER,80);
    m_list.InsertColumn(2,"3",LVCFMT_LEFT,80); HICON hIcon;
    m_ImageList.Create(16,16,ILC_COLORDDB|ILC_MASK,6,6);
    hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
    m_ImageList.Add(hIcon);
    m_list.SetImageList(&m_ImageList,LVSIL_SMALL); m_list.InsertItem(0,"11111");//自动把图像加进来了
    m_list.SetItem(0,0,LVIF_IMAGE,NULL,-1,0,0,0);//去掉图像
    m_list.SetItem(0,1,LVIF_IMAGE,NULL,0,0,0,0);//第二列加入图像