My program works but how do I a newline in there?

357mag

Well-known member
Joined
Mar 31, 2023
Messages
58
Programming Experience
3-5
My program works correctly, but the output in the textbox should show it like this with every answer on a different line:

5 == 5
5 >= 5
5 <= 5

But it's putting everything on the same line like this:

5 == 55 >= 55 <=5

I've tried putting a newline character or a Console.WriteLine everywhere I can think of to no avail.

Here is the code:

C#:
private void buttonCompare_Click(object sender, EventArgs e)
        {
            int firstNumber;
            int secondNumber;

            firstNumber = Convert.ToInt32(textBoxFirstInteger.Text);
            secondNumber = Convert.ToInt32(textBoxSecondInteger.Text);

            if (firstNumber == secondNumber)
            {
                textBoxAnswer.Text = textBoxAnswer.Text + firstNumber + " == " + secondNumber;
                Console.WriteLine();
            }

            if (firstNumber != secondNumber)
            {
                textBoxAnswer.Text = textBoxAnswer.Text + firstNumber + " != " + secondNumber;
                Console.WriteLine();
            }

            if (firstNumber < secondNumber)
            {
                textBoxAnswer.Text = textBoxAnswer.Text + firstNumber + " < " + secondNumber;
                Console.WriteLine();
            }

            if (firstNumber > secondNumber)
            {
                textBoxAnswer.Text = textBoxAnswer.Text + firstNumber + " > " + secondNumber;
                Console.WriteLine();
            }

            if (firstNumber <= secondNumber)
            {
                Console.WriteLine();
                textBoxAnswer.Text = textBoxAnswer.Text + firstNumber + " <= " + secondNumber; 
            }

            if (firstNumber >= secondNumber)
            {
                textBoxAnswer.Text = textBoxAnswer.Text + firstNumber + " >= " + secondNumber;
                Console.WriteLine();
            }
        }
 
I think it's got something to do with I'm still thinking console programming and this is Windows programming I'm doing now.
 
I got it figured out now. I have to write:

textBoxAnswer.AppendText(Environment.NewLine);

I've been doing console programming for so long I'm still in that mindset.
 

Latest posts

Back
Top Bottom