ListBox entry with \n (multiline)

  • Thread starter Thread starter Stefan P.
  • Start date Start date
S

Stefan P.

Hi everyody,

I want to diplay strings of some objects in a LixtBox.
Sometimes the text is longer than my ListBox and a horizontal scrollbar
is displayed.

Is it possible to get the ListBox to display the Text in multiple lines
(per entry)?

I found some controls on CodeProject but they are to overloaded. I just
want to diplay the Text without scrolling (that every word of the stings
is visible on the first sight).

Greetings
Stefan
 
Stefan said:
I want to diplay strings of some objects in a LixtBox.
Sometimes the text is longer than my ListBox and a horizontal scrollbar
is displayed.

Is it possible to get the ListBox to display the Text in multiple lines
(per entry)?

Yes. Implement the ListBox.MeasureItem and ListBox.DrawItem events, and
set ListBox.DrawMode appropriately (OwnerDrawVariable). You'll need to
do the measuring and drawing yourself, unfortunately.

Check out Graphics.MeasureString and Graphics.DrawString methods and the
StringFormat class. It's not too difficult, and you have a lot of
flexibility. For example, you can put icons etc. in the listbox too, if
you like.

-- Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top