Multi-Line Text Box Line Length

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
 
F

Frans Bouma [C# MVP]

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

--
 

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