PDA

Click to See Complete Forum and Search --> : MultiLine Textbox Question


anti_hero0021
Mar 13th, 2007, 05:14 PM
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

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

mendhak
Mar 13th, 2007, 05:19 PM
stringVariable = name + System.Environment.Newline;

mendhak
Mar 13th, 2007, 05:20 PM
And that should have been \r\n. Backslashes, I believe.

anti_hero0021
Mar 13th, 2007, 05:21 PM
Thank you

jmcilhinney
Mar 13th, 2007, 05:54 PM
There are numerous ways to put multiline data into a TextBox, e.g.myTextBox.Text = string.Format("Name: {0}\r\nId: {1}\r\nAverage: {2}\r\nLetter Grade: {3}",
name,
id,
average,
letterGrade);or:myTextBox.Lines = new string[] {"Name: " + name,
"Id: " + id.ToString(),
"Average: " + average.ToString(),
"Letter Grade: " + letterGrade};