0

So I'm making an application for a friend of mine. This app contains a winforms listbox. The listbox contains tweets. Everything works fine but the problem is the length of the tweets. When a tweet is too long, the listbox cuts parts away. Example:

tweetListBox:

Thow tweeted: jalskjdkljasdljlasjkdlasjdlkjaslkjaskljdlasjkd...

It adds dots when the text is too long. I can't resize the listbox because then it's too big. Is there a way to make the text that's bigger then 100 pixels split into different lines?

Rajput
  • 2,597
  • 16
  • 29

2 Answers2

1

If you don't need the selection capabilities of a ListBox, you could switch to a multi line line text box. Use a regular text box and set the multi line property = true. Stretch the control to the appropriate size to match that of the ListBox. Add a new tweet using :

multiLineTweetBox.Append(newTweet + Environment.NewLine);  
ddrjca
  • 472
  • 2
  • 15
  • There's one problem with this solution. Because I append the textbox, it scrolls to the bottom. I want to make the textbox scroll position to stay at the top, or to go to the top after the tweets have loaded in. Is there a way to do that? –  Oct 22 '16 at 12:18
  • @Thow You can add Text by using `multiLineTweetBox.Text += newTweet + Environment.NewLine`. This way, it should stay at the top. – waka Oct 22 '16 at 12:27
  • Works like a charm! Thanks Waka and ddrjca! –  Oct 22 '16 at 13:54
0

It is not possible by just setting a property like WordWrap = true, it simply doesn't exists. A solution already has been given on StackOverflow here:

Winforms DotNet ListBox items to word wrap if content string width is bigger than ListBox width?

Community
  • 1
  • 1
Bouke
  • 1,531
  • 1
  • 12
  • 21
  • This method makes the listbox drawmode to ownerDrawVariable. If I do that it doesn't draw anything anymore. Is there a better method? –  Oct 22 '16 at 11:41
  • According to the responses on the provided solution, it should work. You could create your own user control. – Bouke Oct 22 '16 at 11:54