C# TextBox and Hard Line Breaks

M

Mike

I need my textbox to work more smoothly with respect to line breaks.
When I have data pulled from the database into a textbox there are hard
line breaks at the end of each line (by definition how Lines property
works, right?). But, the textbox is used for editing data previously
entered into the database. Ideally, what I want is just a hard break
at the end of each paragraph so users can smoothly enter or remove data
anywhere without pushing hard line breaks around into the middle of
subsequent lines or have lines broken in the middle.

Any suggestions on how to accomplish this would be greatly appreciated.

Mike
 
J

James Curran

I'm a bit confused by your question -- Every time you mention TextBox,
you mention your database in the same sentence, so it's not clear where the
hard-line breaks are coming from.

You to not need to use the Lines property to retrieve the text. You
could use the Text property, which should not have the line breaks in it.
 
M

Mike

Hi James,

I don't think the requirements for this project are that demanding, but
I have not been able to make it work well yet. I am using the text box
to present text that has previously been stored in the database as a
set of lines (with text type, text line sequence and text description
-- which is the actual text I need to present to be edited). The lines
can be no longer than 74 characters long in the database so I am using
courier new so that wordwrap occurs in the textbox at 75 characters.
Because the text actually has some formatting already done to it (like
below) I must maintain that for readability. I want to use the Lines
property to do a foreach loop and save the text back to the database
while attaching a line sequence and text type. Based on the
documentation for the text box I can get an array of strings (each a
line), but which has a hard line break where word wrap occurs. (like
right below)

Example one as text begins in the text box -- \r\n at end of each row
1)
Dr. Smith closed the incision at 11:43 followed by Dr. Johnson \r\n
who had not gotten any sleep in at least three days and was\r\n
dangerous when let loose......\r\n
Anesthesia Time: 2:33\r\n

The problem is if someone edits and puts in new text like in example 2.

2) Text has been added to the second line which pushes the \r\n down
into the next row
and makes the formatting messy. Surgeons hate this.

Dr. Smith closed the incision at 11:43 followed by Dr. Johnson \r\n
who had not gotten any sleep in at least three days and was
exceedingly\r\n
dangerous when let loose......\r\n
Anesthesia Time: 2:33\r\n

http://msdn.microsoft.com/library/d...temwindowsformstextboxbaseclasslinestopic.asp

I am sending a message EM_FMTLINES which does a nice job giving me line
breaks where the word wrap occurs and so I get a nice array to loop
through and save to the DB, but it still leaves the \r\n in the middle
of lines as above after 'exceedingly'. Same thing occurs when text is
deleted (i.e text below does not scoot up naturally as there may be
hard line breaks in the middle of one or more lines now).

Sorry about the length, but trying to got a good explanation.

Thanks,
Mike
 

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