0
votes

Background:

I am writing a C# form program with MSVS 2010. The form has 2 textboxes: textBox1 (input, single line) and textBox2 (output, multiple lines).

I want to enter a string in textBox1 and when a condition is met it prints some text to textBox2. I want to be able to enter multiple inputs and print output to textBox2 and not erase the previous output.

Questions:

  1. My question is can this be done?
  2. If not can you use multiple text boxes and move the output to the next higher value text box?
5
wpf? winforms? asp.net? silverlight? (etc)Muad'Dib
I am new to C# also. I am assuming .netajaustin12
Are you new to frameworks?!?!?!?!MyKuLLSKI
@MyKuLLSKI Yes I am. The only language I had an actual class on is C. I have had to teach myself a little of C++ and C# and having problems as I go.ajaustin12

5 Answers

2
votes

All you need to do is keep appending to the text property.

string output = "Hi!";
outputBox.Text += output + Environment.NewLine;

This is, of course, after you've given your textbox a more meaningful name than textBox2

Bonus: You can also prepend to the text if you prever new output to appear at the top:

outputBox.Text = output + Environment.NewLine + outputBox.Text;
1
votes

Yes, it can be done. Just append the text from textBox1 to the existing text in textBox2. You can set up some kind of event handler to check if the condition is met.

1
votes

Yes that can be done. You just need to concatenate the existing text in textBox2 with the new text you want to add.

Here is a very simple way to do this:

textBox2.Text = textBox2.Text + Environment.NewLine + "new text"
1
votes

sure, all can be done:

1) "enter a string in textBox1 and when a condition is met "

this can be done in several ways, if condition is user derived event (such as key press) this can be done using events. if condition is checked separably by program then simple

if(condition){
  textBox1.Text += output;
}

will suffice.


2) "I want to be able to enter multiple inputs"

multiple inputs simply means reading more textboxes


3) "print output to textBox2 and not erase the previous output."

this can be done as follows:

// append at end
textBox1.Text += output;
// append at start
 textBox1.Text = output + textBox1.Text;
0
votes

You probably want to use an ItemsControl to display each line, then you just add the new line to the List source.

http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.aspx