Write a long string in listbox( multiple lines)

Answered Write a long string in listbox( multiple lines)

  • domenica 19 agosto 2012 21:55
     
     

    Hi friends,

    I want to put a long string in list box, which its width is more than width of list box.This is my problem:I want to put this string in multiple lines instead of using horizontal scroll.I mean when the string exceeds the end of line, it should back to the first of the next line.

    Thanks

Tutte le risposte

  • domenica 19 agosto 2012 23:37
     
     

    It is possible to do that by customizing the list box with the owner-draw feature. Here is an example that makes a multiline list box:

    http://www.codeproject.com/Articles/135855/Owner-Drawn-CListBox

  • lunedì 20 agosto 2012 07:02
     
     

    Thank you "Scott McPhillips" for your reply.

    Is there any easier way to approach the mentioned purpose?I mean instead of using list box,can we not use something else to do that?(show a long string in a small box)

  • lunedì 20 agosto 2012 11:56
     
     Con risposta
    Thank you "Scott McPhillips" for your reply.
     
    Is there any easier way to approach the mentioned purpose?I mean instead of using list box,can we not use something else to do that?(show a long string in a small box)
    Why not use a multi-line edit control?
     
    What kind of application is this (Win32, MFC, WinForms...)?
     

    David Wilkinson | Visual C++ MVP
    • Contrassegnato come risposta moottii martedì 21 agosto 2012 19:48
    •  
  • lunedì 20 agosto 2012 14:18
     
     

    It is MFC

    There is no difference for me to use editbox or listbox.

    I just need a small box to show a long string.for example if my string is

    str="Hello World!Hello World!";

    It is not enough wide to show whole the string.So it shows: Hello World!Hel

    I want the result to be something like this:

    Hello World!

    Hello World!

    Thanks

  • lunedì 20 agosto 2012 14:59
     
     

    Editable Multi-line ListBox

    Thanks


    Rupesh Shukla

  • lunedì 20 agosto 2012 15:55
     
     
    Then the edit control with the multiline style set does what you want.
  • martedì 21 agosto 2012 09:15
    Moderatore
     
     

    Hi moottii,

    I guess that multi-line edit control would be an easy way for you. If you don't use any controls, you have to draw a box and then draw the text inside the box. That is more complicated than dragging a control from the Toolbox and verify a few codes to make it work as you want.

    Set the edit control with multi-line style:

    in the property window of an edit box, set "Multiline" as true and set "Auto HScroll" as false at the same time.


    Damon Zheng [MSFT]
    MSDN Community Support | Feedback to us

  • martedì 21 agosto 2012 18:10
     
     
    Why can't you use a static control and show it in mouse over.Use ItemFromPoint() to get the string under mouse cursor

    Thanks, Renjith V R