A simple, scrollable, output display window

G

Guest

I'm writing a visual studio C# program. I have my form with a number of
controls. I also want a simple scrollable window in which I can
programmatically add text as the program is running. I want to use it to show
diagnostic output as the program runs. It should be fairly simple to do, yes?
Well, I can't figure out what control to use. How do I do this?
 
P

Peter Duniho

I'm writing a visual studio C# program. I have my form with a number of
controls. I also want a simple scrollable window in which I can
programmatically add text as the program is running. I want to use it to show
diagnostic output as the program runs. It should be fairly simple to do, yes?
Well, I can't figure out what control to use. How do I do this?

The TextBox control can be used as a simple implementation of something
like that.

Pete
 
G

Guest

You would think so, wouldn't you? I tried that and was not successful in
getting it to do what I want. It doesn't (as far as I can see) have anything
like an "Add" method, to simply add new text to the existing text. I tried
retrieving the existing text, adding a newline character and the new text to
it and putting that back into the textBox via the Text field. But it igores
the newline character, so it all runs together.

In addition, the TextBox class is described in the MS documentation as
"Provides a text-based control that allows the user to enter text.". I don;t
want to allow the user to enter text into this thing. I just want to display
some text programmatically.
 
S

Stephany Young

Well set the ReadOnly property of the TextBox control in question and then
the user won't be able to enter text into 'this thing'.

Have a closer look at the methods exposed by the TextBox class. You will
find one that allows you to append text to what is already there.
 
P

Peter Duniho

You would think so, wouldn't you?

Not only would I, I do.
I tried that and was not successful in
getting it to do what I want.

Not being successful yourself does not mean that the control is
necessarily the problem.
It doesn't (as far as I can see) have anything
like an "Add" method, to simply add new text to the existing text.

Did you see the AppendText() method? It does exactly that.
I tried
retrieving the existing text, adding a newline character and the new text to
it and putting that back into the textBox via the Text field. But it igores
the newline character, so it all runs together.

As long as you've set the Multiline property, then Environment.NewLine
characters in the text will create line breaks.
In addition, the TextBox class is described in the MS documentation as
"Provides a text-based control that allows the user to enter text.". I don;t
want to allow the user to enter text into this thing. I just want to display
some text programmatically.

So set the ReadOnly property to true.

Pete
 

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

Top