How to Create Multi Line Text ?
VB.NET :
in vb.net, "&vbnewline&" is used to add a new line in the messagebox.show();
e.g.
messagebox.show("this is first line" & vbnewline & "this is second line");
C#.NET :
In C# (like most C derived languages), escape characters are used to denote special characters such as return and tab, and + is used in place of & for string concatenation.
To make your code work under C# you’ve got two options... the first is to simply replace the vbNewLine with the return escape character \n ala:
MessageBox.Show("this is first line" + "\n" + "this is second line");
The other method, and more correct is to replace it instead with Environment.NewLine which theoretically could change depending on the system you are using (however unlikely).
MessageBox.Show("this is first line" + "Environment.NewLine" + "this is second line");
Also I'd like to add; If you would like to take advantage of ``Environment.NewLine'' as Brendan suggested you could do something like this to make it more legible IMO::
Console.WriteLine( "This is Line1{0} This is Line2{0}", Environment.NewLine );
[Output]
This is Line1
This is Line2
// Or...
MessageBox.Show( string.Format( "This is Line1{0} This is Line2{0}", Environment.NewLine ) );
[Output]
This is Line1
This is Line2
// Or...
string msg = string.Format( "This is Line1{0} This is Line2{0}", Environment.NewLine );
MessageBox.Show( msg );
[Output]
This is Line1
VB.NET :
in vb.net, "&vbnewline&" is used to add a new line in the messagebox.show();
e.g.
messagebox.show("this is first line" & vbnewline & "this is second line");
C#.NET :
In C# (like most C derived languages), escape characters are used to denote special characters such as return and tab, and + is used in place of & for string concatenation.
To make your code work under C# you’ve got two options... the first is to simply replace the vbNewLine with the return escape character \n ala:
MessageBox.Show("this is first line" + "\n" + "this is second line");
The other method, and more correct is to replace it instead with Environment.NewLine which theoretically could change depending on the system you are using (however unlikely).
MessageBox.Show("this is first line" + "Environment.NewLine" + "this is second line");
Also I'd like to add; If you would like to take advantage of ``Environment.NewLine'' as Brendan suggested you could do something like this to make it more legible IMO::
Console.WriteLine( "This is Line1{0} This is Line2{0}", Environment.NewLine );
[Output]
This is Line1
This is Line2
// Or...
MessageBox.Show( string.Format( "This is Line1{0} This is Line2{0}", Environment.NewLine ) );
[Output]
This is Line1
This is Line2
// Or...
string msg = string.Format( "This is Line1{0} This is Line2{0}", Environment.NewLine );
MessageBox.Show( msg );
[Output]
This is Line1
No comments:
Post a Comment