Line breaks in text boxes

G

Guest

hi,

i have a button and when it is clicked, a textbox's text will change. the
text, however has line breaks in it. here is my code for the button's click
event:

textBox1.Text = "You clicked the button!\n\n\n\n\nif you exit the
application (Alt+F4), you can click the button again!";

the line breaks appear as small squares. how do i display line breaks
 
K

Kerem Gümrükcü

Hi,


this happens beacause of the different ascii codes.
I had the same problem and i sloved it that way:

This is a part of a huge class, that i wrote for stream
manipulation purposes:

internal sealed class DataStreamHelper{

internal static string PrepareStringForTextBox(string StringStream){
string _ready_stream;
_ready_stream = Regex.Replace(StringStream,"\n","\r\n");
return _ready_stream;
}

internal static string ReplaceString(string InputStream,string
PatternString, string ReplacementString){
string _ready_stream;
_ready_stream =
Regex.Replace(InputStream,PatternString,ReplacementString);
return _ready_stream;

}
}

Check out the PrepareStringForTextBox() Function. It means: Find the \n and
replac it with \r\n.
This will work...

Best Regards

Kerem Gümrükcü
 
G

Guest

Instead of explicitly saying \r\n you could use System.Environment.NewLine
instead then you donot need to worry about the different codes on different
systems.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Two things:

Set
TextBox.MultiLine = true;

and then use Environment.NewLine to get the characters sequence that
represent a new line.


cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top