473,499 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

word wrap

7 New Member
the below code is for word wrap where user can specify no of char per line
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
  1. private void txtBody_TextChanged(object sender, System.EventArgs e)
  2.         {
  3.             #region "wrap"     
  4.             string[] tempArray = new string [txtBody.Lines.Length];           
  5.             tempArray = txtBody.Lines;        
  6.  
  7.             int PrevSel = txtBody.SelectionStart;       
  8.             string Op = "";      
  9.  
  10.             //No. of chracter user can specify
  11.             int maxLength = Convert.ToInt32(textBox1.Text);           
  12.             bool change= false;       
  13.  
  14.             for(int cou = 0; cou < tempArray.Length ; cou++)
  15.             {        
  16.                 if (tempArray[cou].Length > maxLength)             
  17.                 {           
  18.                     string[] words = tempArray[cou].Split(' ');
  19.                     int currentLineLength = 0;           
  20.                     string currentLine = "";            
  21.                     foreach(string currentWord in words)
  22.                     {            
  23.                         if(currentWord.Length >= 0)            
  24.                         {               
  25.                             if(currentWord.Length >= maxLength)              
  26.                             {               
  27.                                 Op += currentWord.Insert(maxLength, "\r\n");
  28.                                 break;               
  29.                             }            
  30.                             if(currentLineLength + currentWord.Length + 1 < maxLength)
  31.                             {                
  32.                                 currentLine += currentWord + " ";
  33.                                 currentLineLength += currentWord.Length +1;
  34.  
  35.                             }            
  36.                             else             
  37.                             {               
  38.                                 Op +=currentLine.Insert(currentLineLength, "\r\n");
  39.                                 currentLine = currentWord + " ";   
  40.                                 currentLineLength = currentWord.Length;
  41.                             }
  42.                         }
  43.                     }         
  44.                     if(currentLine !="") 
  45.                         Op += currentLine;
  46.  
  47.                     PrevSel++;           
  48.                     change = true;      
  49.                 }
  50.                 else
  51.                 { 
  52.                     Op += tempArray[cou] + "\r\n";
  53.                 }
  54.                 if(change)
  55.                 {
  56.                     txtBody.Text = Op;
  57.                     txtBody.SelectionStart = PrevSel;
  58.                 }
  59.             }
  60.             #endregion
  61.  
  62.         }
  63.  
Sep 19 '07 #1
1 990
Plater
7,872 Recognized Expert Expert
Wouldn't it be easier to just use the properties of the textbox to show the characters around?
They support word-wrapping and the amount of characters per line(in a way)
Sep 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
5580
by: yawnmoth | last post by:
word wrapping normally treats some spaces as line feeds, if there hasn't been a line feed for quite a while. so while a string with eighty consecutive a's might not word wrap, a space placed...
10
2305
by: Douglas G | last post by:
I've tried various ideas on this problem, but I don't see word wrapping. Can you point out what is wrong? It's a K&R exercise, and I'm still new to programming. Other pointers would be helpful...
10
23260
by: Jeff B. | last post by:
Has anyone come across a decent algorithm for implementing word wrap features in .net printing? I have a small component that uses basic printing techniques (i.e. e.Graphics.DrawString in a...
10
72644
by: Lorenzo Thurman | last post by:
I have a table cell that I want to wrap text inside of. I've tried both hard and soft wrap, but Firefox refuses to obey. IE 6&7 handle the wrap just fine. Does anyone know how I can fix this?
0
3986
by: funeeldy | last post by:
I need to locate a particular table in a document. I cannot hardcode the table number since it could be different in every doc. I do have some header text that comes right before it consistently,...
8
6922
by: gazza67 | last post by:
Hi, I want to do something that I thought would be simple but i cant seem to work it out, perhaps someone out there could help me. I want to browse for a file (it will be a word document),...
4
12411
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
1
8755
by: winston.heng | last post by:
Hi, Thanks for reading this posting. I have been cracking my head on solving the infinite loop when i call the following section code. Any help or advise is greatly appreciated =D Thanks in...
6
4601
by: Eric Layman | last post by:
Hi, I have fields from textareas. With a click of a button, php is able to grab these fields and by using header(), convert the output to Ms Word doc. But the outcome of the word doc...
1
4988
by: vedika | last post by:
Hello, I have problem with word-wrapping. When width is given in pixel style="word-wrap:word-break" works well but when it is given in percentage then it is not working. <table border="1"...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.