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.
HemantPosted Sep 20, 2007, 1:25 AM
Suppose user types:
"This is trial message, plz ignore this.
This is trial message, plz ignore this
This is trial message, plz ignore this"
Now if he return back to 1 or 2 line and modify the content like enter som text, then it shud shit to right properly, but here not like that, the words got cut and it looked messed up.
I tried every possible way to rectify the problem, but could not fix it, if u plz test the code and rectify it, it will b really helpful of u.
code is for text_change event in c#.net, for richtext box control, plz do this favour as i m really in need.
thaks & regards
kavitaPosted Sep 19, 2007, 8:17 AM
U don't specify your problem according to me u are talking about when u enter more text in 1 line some text shift to next line if yes then it is due to length u specify in textbox1. increase it then no problem will occur.
best of luck!!