开发者

adding a windows form object to listbox

I'm creating a twitter client in C#. I want to put every tweet as an element of a listbox. I created a windows form that represents a tweet(it has a picture, and labels).

My problem is that when i can't see the tweets when i add them to the listbox. After addi开发者_如何学Cng 3 tweets(windows form objects), the listbox has 3 blank elements in them, but i can't see anything of it.

How can i add a windows form object to a listbox?

(these forms are working fine, because i can see them if i use the ShowDialog method)

please help


You can add a Form object to the ListBox.Items collection but the only thing you'll ever see is the type name of the form. ListBox is not capable of rendering controls as its items.

The efficient solution is to implement the ListBox.DrawItem event and custom draw the tweet. There's a good example of such an event handler in the MSDN Library documentation for the event.

The slow solution is to add controls to a Panel's Collection property with its AutoScroll property set to true. That cannot be a form, it must be a UserControl.


You may want to look into implementing it using WPF. Where you can pretty much put anything inside a listbox.


Some thoughts:

  1. You'd do better to work with custom controls, rather than a whole form
  2. A listbox can't have controls on it... consider a ListView: http://www.codeproject.com/KB/list/ListViewEmbeddedControls.aspx
  3. Some example code of what you're trying will help us zoom in on what you're doing

HTH, James


I don't think ListBox can display anything but a text string for each element, so you won't be able to see an image of each form if that's what you were hoping for. You might try using FlowLayoutPanel instead to manage a list of controls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜