Hemant

Hemant

  • NA
  • 3
  • 0

Plz need help

Sep 19 2007 6:29 AM

 

 

private void txtBody_TextChanged(object sender, System.EventArgs e)

{

#region "wrap"

string[] tempArray = new string [txtBody.Lines.Length];

tempArray = txtBody.Lines;

int PrevSel = txtBody.SelectionStart;

string Op = "";

//No. of chracter user can specify

int maxLength = Convert.ToInt32(textBox1.Text);

bool change= false;

for(int cou = 0; cou < tempArray.Length ; cou++)

{

if (tempArray[cou].Length > maxLength)

{

string[] words = tempArray[cou].Split(' ');

int currentLineLength = 0;

string currentLine = "";

foreach(string currentWord in words)

{

if(currentWord.Length >= 0)

{

if(currentWord.Length >= maxLength)

{

Op += currentWord.Insert(maxLength, "\r\n");

break;

}

if(currentLineLength + currentWord.Length + 1 < maxLength)

{

currentLine += currentWord + " ";

currentLineLength += currentWord.Length +1;

}

else

{

Op +=currentLine.Insert(currentLineLength, "\r\n");

currentLine = currentWord + " ";

currentLineLength = currentWord.Length;

}

}

}

if(currentLine !="")

Op += currentLine;

PrevSel++;

change = true;

}

else

{

Op += tempArray[cou] + "\r\n";

}

if(change)

{

txtBody.Text = Op;

txtBody.SelectionStart = PrevSel;

}

}

#endregion

}

 

the above code is for text change event, in c# for word wrap, where user can specify no. of char per line.

There is bit of problem in this ,

suppose user enter 3-4 lines like:

"this is trial msg plz ignore this.

this is trial msg plz ignore this.

this is trial msg plz ignore this."

now if he comes back to 1st line and enter text in between then problem occur.

plz anyone who can help , i need it really badly.


Answers (2)