Devid Demetz
Devid Demetz

Reputation: 125

How to put multiple lines of text into a textbox

I have something like this:

enter image description here

and i would like to have something like this:

enter image description here

Upvotes: 0

Views: 187

Answers (5)

James Wang
James Wang

Reputation: 189

MessageBox.Show("It's Felix Birthday\nIt's DesBirthday\nIt's Fffffffs Birthday!");

Just put "\n" where you want to new line

Upvotes: 0

sylmz
sylmz

Reputation: 55

By using TextWrapping, you will be able to use multiline textbox.
TextWrapping="Wrap" MaxLines="2" Width="150"

Upvotes: -1

Ted
Ted

Reputation: 173

You should use Environment.NewLine as suggested by Jonesopolis. See the documentation here, the caracters for the new line depend on the system you are targeting. Let the .NET framework know what a new line is.

You can use it like that

string str = String.Format("this text{0}is on three{0}lines", Environment.NewLine);

Or, if you're using the last version of C# (can be less readable if you have a lot of new lines) :

string newLine = Environment.NewLine;
string str = $"this text is{newLine}on three{newLine}lines";

Upvotes: 3

Nico
Nico

Reputation: 12683

As stated before\r\n is a good use to insert new lines. Alternatively (and my personal choice) is to use Environment.NewLine which effectively does the same thing. However this is based on the Enviroment and therefore should be cross environment compatible (all-be-it no other WPF environment exists).

Something like

string message = string.Format("It's Felix Birthday{0}It's DesBirthday{0}It's Fffffffs Birthday!", Environment.NewLine);

Really this will just produce the same result as entering in the \r\n but also makes it a bit more readable.

Upvotes: 0

Kahbazi
Kahbazi

Reputation: 14995

Insert "\r\n" where ever you want to add line

"It's Felix Birthday\r\nIt's DesBirthday\r\nIt's Fffffffs Birthday!"

Upvotes: 3

Related Questions