Results 1 to 6 of 6

Thread: [RESOLVED] New line in Textbox..

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Resolved [RESOLVED] New line in Textbox..

    Help please..How can i put a new line in my textbox. I have tried the code below but it does not work the way i want it.

    Code:
    txtMessage.Text = "First Line Message \n\n" + " Second line message";
    It shoudl be like this:

    First Line Message

    Second line message
    but the ouput is:
    Attached Images Attached Images  

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

    Re: New line in Textbox..

    "\n" is a line feed character. A line feed character alone is the line break indicator on Unix systems. On Windows systems the line break indicator is a carriage return character followed by a line feed character:
    C# Code:
    1. txtMessage.Text = "First Line Message\r\n\r\nSecond line message";
    Note that Environment.NewLine will return a string containing the line break indicator for the current system. On Windows systems it will return a carriage return followed by a line feed.
    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

  3. #3
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502

    Re: New line in Textbox..

    "\n" is fine, both on linux and windows in my oppinion.
    I always use "\n" in C#, that's also how I did it in C++.

    But you need to set the multiline property of your textbox to true. I guess that's just what you forgot, right?
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

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

    Re: New line in Textbox..

    If that was the problem then the TextBox could not be that size. With the Multiline property set to False the TextBox doesn't support changing the Height.

    While Windows does support the use of "\n" as a line break it is basically through translation because "\r\n" is the proper line break for Windows. As such it appears that the Windows.Forms.TextBox does NOT support "\n" alone. I tested it myself and without the carriage return the TextBox will display the line feeds as place-holders only. Maybe there's a way around that but by default that's what happens.
    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

  5. #5

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: New line in Textbox..

    Thanks for info JM. BramVandenbon, I think multiline property of my textbox is nothing got to do with my problem becuase it is already set to true even before I created this thread. But anyway, Thanks for the inputs.

  6. #6
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502

    Re: [RESOLVED] New line in Textbox..

    Strange, I'm wrong on this one indeed.

    It's particulary strange, cause when you print text in messageboxes, the "\n" is enough.

    Oh well, excuse me for the missleading information.
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

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