CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 1999
    Posts
    19

    Center text in a listbox?

    Hiya!

    I'm wondering if its possible to center the text in a CListBox. Both vertical and horisontel.

    Thanks
    Magnus


  2. #2
    Join Date
    Mar 2000
    Location
    Sherbrooke,Qc.,Canada
    Posts
    4

    Re: Center text in a listbox?

    One of the best way is to use an ownder-deawn list box
    1 ) modify your resource to have an Owner draw and Has string styles
    2 ) intercepeit the owner draw message
    3 ) Draw your text
    ....
    CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
    CRect rcLine(lpDrawItemStruct->rcItem);
    GetText(lpDrawItemStruct->itemID, strChaine);

    there you have a CDC, a CString and a Rect.
    DrawText(... DT_CENTER | DT_VCENTER)

    there are many samples in code guru

    One tip you are supposed to fraw the line diffrently depending of the focus and state
    if ((lpDrawItemStruct->itemState & ODS_SELECTED)
    or (lpDrawItemStruct->itemAction & ODA_SELECT))
    {
    CRect Unrect(lpDrawItemStruct->rcItem);
    pDC->InvertRect(&Unrect);
    ...



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured