tags:

views:

339

answers:

5

I'm working on an application that gets content from feeds in C#. This content should then be displayed on the form.

My question is what control should I use to hold this data? Should I be creating a new label (dynamically) for each item? Someone suggested to me that I should use a RichTextBox but this content shouldn't be editable.

If it helps, I'm a web developer. I'd normally output my content in HTML and would use headings, paragraphs etc. for my content. Am I looking at this the wrong way?

If this seems like a very basic question, it probably is. I'm very new to Windows Forms.

Thanks, Ross

+1  A: 

If you're comfortable with HTML, I'd say go with a WebBrowser control. It's easy to use, you're familiar with HTML, so you can have complete control over what you want to display. No use in trying to reinvent the wheel.

EDIT: If you strictly want to stick with Winforms though, and feel a WebBrowser won't cut it, I'd probably suggest a DataGridView. You can host all kinds of content in there as well as images and links, and you can turn off all kinds of editing. You can even get rid of the grid lines, so it won't have the "look" of a grid.

BFree
+1  A: 

A list box or a list view are also good alternatives. The best feature is that you can easily remove content from the top while adding content to the bottom, making scrolling very easy to implement

What sort of content is it? Is it styled (e.g. has fonts, colours, links)

Conrad
+1  A: 

Here's why WPF was invented. It is much, much more flexible at putting markup-based content onto your applications than WinForms is. If you can use WPF, check that out (though you will have to ride a learning curve to do it).

Otherwise, you can dynamically create label controls and put them on Panel controls to somewhat control the layout. If you must use WinForms and you must use the common controls, stick with the TextBox or the RichTextEditor and disable editing on them.

Dave Markle
If you need only one form for this using WPF, can this be contained within a larger WinForms app?
P a u l
+1  A: 

I have a WCF feed of data from a web service. In the windows forms application I created a user control to show one unit of data. For each data unit that comes in from the web service, I create an instance of the user control. They are added vertically to a scrolling window. The user control allows me to stylize the information as needed, and the user can interact with the content via buttons, etc.

P a u l
+1  A: 

DataGridView is good enough for this. See this example. Of course you can improve on look and feel :)

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        List<Item> items = new List<Item>();

        items.Add(new Item("item 1"));
        items.Add(new Item("item 2"));
        items.Add(new Item("item 3"));
        items.Add(new Item("item 4"));


        dataGridView1.DataSource = items;
    }
}
class Item
{
    public string ItemName { get; set; }
    public Item(string name)
    {
        ItemName = name;
    }

}
chikak
I tried your example and this looks like a good (and simple!) way to do it.
Ross