views:

51

answers:

2

I want to use a control to notice users what are happening and what've done. It's like a multiline textbox, each line contains a notice, such as:

Connecting to database...done
Current datetime: 
Inserting data into database 10/1000...done
Inserting data into database 20/1000...done
...
Inserted data into database
Current datetime:

I tried textbox, but it seems to be too complicated to manipulate many lines.

Is there a better control to do this? If textbox was the best choice, so how can I do this?

Thanks in advance!

+2  A: 

I would use a listbox. Set it to SelectionMode.None. Add to the items collection. If you have enough lines to scroll off the screen you will need to adjust the scrollbar to the bottom manually. Do so by setting the listbox TopIndex to the number of lines - 1.

Kevin Stafford
Listbox seems to be much easier approach. I like it :D. But one drawback: user cannot select or copy the text log. I'm thinking about it.
Vimvq1987
+2  A: 

I've seen people use ListBoxes and TextBoxes. I usually use RichTextBoxes because then I can easily apply some simple styles and colouring, but it's probably overkill.

I found this method in one of my "just-playing-around" projects:

private void writeToLog(String text, SolidColorBrush color)
{
    TextRange tr = new TextRange(logTextBox.Document.ContentEnd, logTextBox.Document.ContentEnd);
    tr.Text = text;
    tr.ApplyPropertyValue(TextElement.ForegroundProperty, color);
}
Maiku Mori
This question is tagged 'WinForms' : you are using the WPF RichTextBox here, not WinForms.
BillW