Results 1 to 5 of 5

Thread: MultiLine Textbox Question

  1. #1

    Thread Starter
    New Member anti_hero0021's Avatar
    Join Date
    Nov 2005
    Posts
    8

    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

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: MultiLine Textbox Question

    stringVariable = name + System.Environment.Newline;

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: MultiLine Textbox Question

    And that should have been \r\n. Backslashes, I believe.

  4. #4

    Thread Starter
    New Member anti_hero0021's Avatar
    Join Date
    Nov 2005
    Posts
    8

    Re: MultiLine Textbox Question

    Thank you

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MultiLine Textbox Question

    There are numerous ways to put multiline data into a TextBox, e.g.
    C# Code:
    1. myTextBox.Text = string.Format("Name: {0}\r\nId: {1}\r\nAverage: {2}\r\nLetter Grade: {3}",
    2.                                name,
    3.                                id,
    4.                                average,
    5.                                letterGrade);
    or:
    Code:
    myTextBox.Lines = new string[] {"Name: " + name,
                                    "Id: " + id.ToString(),
                                    "Average: " + average.ToString(),
                                    "Letter Grade: " + letterGrade};
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width