Multi-Line Text Box Line Length

  • Thread starter Thread starter Jow Blow
  • Start date Start date
J

Jow Blow

I am trying to make a word wrap type function for a multi line text box
field that will be saved to a text file. The word wrap property looks good
in the app but when saved to a text file the line goes on and on where there
is not a new line character in the text box.

Here's kinda what I'm looking at:

//start snippet
public void WrapIt()
{
int lines = txtMessage.Lines.Length;
string[] tempArray = new string[txtMessage.Lines.Length];
for (int i =0; i < lines; i++)
{
if (txtMessage.Lines.Length < 69)
{
tempArray.SetValue(txtMessage.Lines + "\n", i);
}
else
{
//PART WHERE I'M STUCK
}
}

txtMessage.Clear();
for (int i=0;i<tempArray.Length; i++)
{
txtMessage.AppendText(tempArray);
}
}

//end snippet

Many thanks in advance,
Joe
 
Jow said:
I am trying to make a word wrap type function for a multi line text box
field that will be saved to a text file. The word wrap property looks good
in the app but when saved to a text file the line goes on and on where there
is not a new line character in the text box.

Here's kinda what I'm looking at:

//start snippet
public void WrapIt()
{
int lines = txtMessage.Lines.Length;
string[] tempArray = new string[txtMessage.Lines.Length];
for (int i =0; i < lines; i++)
{
if (txtMessage.Lines.Length < 69)
{
tempArray.SetValue(txtMessage.Lines + "\n", i);
}
else
{
//PART WHERE I'M STUCK
}
}

txtMessage.Clear();
for (int i=0;i<tempArray.Length; i++)
{
txtMessage.AppendText(tempArray);
}
}

//end snippet


You do write a \r\n to the file, right? Use Environment.NewLine to
write the newlines in your text to the file. Some textboxes can't deal
with \r\n and want \n only, though a textfile should have \r\n

Frans

--
 
Back
Top