Line breaks in text boxes

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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ü
 
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.
 
Hi,

Two things:

Set
TextBox.MultiLine = true;

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


cheers,
 
Back
Top