on text_change event
there is problem if anyone can help me to remove this, plz plz
if user enter 3-4 lines:
"This is trial message plz ignore.
This is trial message plz ignore.
This is trial message plz ignore.
This is trial message plz ignore."
and now when user comes back to first line and enter some data in between, then the problem starts,
Expand|Select|Wrap|Line Numbers
- 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
- }