MultiLine Textbox Question
I have a simple question. I'm just starting to program in the GUI for C#. My teacher wants us to output data in a multiline textbox, but I can't figure out how to do that.
For example, the program we are doing is calculating grades. The button we are clicking is supposed to output all information in to a textbox in a list format. So:
Name: Jason
Id: 1234
Average: 95
Letter Grade: A
My teacher is telling us that this needs to be in a single string like
Code:
stringVariable = name + "/r/n" +
but I know/hope that there is a better way to do this. Any help would be appreciated. Thanks,
- anti_hero0021
Re: MultiLine Textbox Question
stringVariable = name + System.Environment.Newline;
Re: MultiLine Textbox Question
And that should have been \r\n. Backslashes, I believe.
Re: MultiLine Textbox Question
Re: MultiLine Textbox Question
There are numerous ways to put multiline data into a TextBox, e.g.
C# Code:
myTextBox.Text = string.Format("Name: {0}\r\nId: {1}\r\nAverage: {2}\r\nLetter Grade: {3}",
name,
id,
average,
letterGrade);
or:
Code:
myTextBox.Lines = new string[] {"Name: " + name,
"Id: " + id.ToString(),
"Average: " + average.ToString(),
"Letter Grade: " + letterGrade};