1 Attachment(s)
[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:
Quote:
First Line Message
Second line message
but the ouput is:
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:
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.
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?
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.
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.
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.