By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,481 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,481 IT Pros & Developers. It's quick & easy.

TextBox WordWrap and Lines Property

P: n/a
Hi All,

I am working with a textbox in C# which pulls a set of lines (stored in
the database as text_type, text_line_seq, text_desc). I am using three
text boxes to display previously entered text for selected users
(surgeons) to edit. Each type of line has a specific maximum length
(55,56, and 74 characters). The textbox must allow the users to format
their text (see EXAMPLE TEXT below) pretty much with just spacing.

I have the textbox properties set to multiline edit and I am appending
"\r\n" to each line as I pull it from the database and put it in the
textbox.

My problem is when a user typically adds a substantial amount of text
wordwrap will push "\r\n" down to the next line. When saving back to
the database I am using a foreach(string Line in Lines) to save the
data and the result is that the line runs over the maximum length
allowed for the line.

Ideally, I simply would like to insert Environment.Newline wherever
there is a wordwrap. I have been trying to use EM_FMTLINES (see
EM_FORMATLINES EXAMPLE) , but it has not worked so far. I am not
sure where I should call the method (SendMessage) and exactly whether
this will result in what I require.

I keep telling myself I must be making this more difficult than it
needs to be, but the solution has not appeared obvious so far.

Thanks for any suggestions.

Mike
EM_FORMATLINES EXAMPLE:

public static extern int SendMessage(IntPtr hWnd,int Msg,int
wParam,int lParam);

public const int EM_FMTLINES = 200;

SendMessage(tbxDiagnosis.Handle, EM_FMTLINES, 0, new IntPtr(0));

EXAMPLE TEXT:

NOTE: This procedure was done at the Hospital, in conjunction
with the Otolaryngology Service and Plastic Surgery. This patient is
having a free jejunal graft for replacement of his cervical esophagus,
and
the other parts of the procedure were performed by Dr. X and Dr.
Y.
ANESTHESIA: General endotracheal
ESTIMATED BLOOD LOSS: Less than 20 cc
DESCRIPTION OF PROCEDURE: Under satisfactory general anesthesia, after

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
List,

Here is a solution for my problem

private string[] GetAllLines(TextBox _pTb, bool _pKeepHardLineBreaks)
{
try
{
SendMessage(_pTb.Handle, EM_FMTLINES, 1, new IntPtr(0));
}
catch(Exception e)
{
MessageBox.Show(e.Message.ToString(), "Error sending API
message");
}
string[] result = {};
result = Regex.Split(_pTb.Text,@"\r\n");

for (int i = 0; i < result.Length; i++)
{
if (result[i].Length > 0 && result[i].Substring(result[i].Length -1,
1) == "\r")

{
result[i] = result[i].Substring(0,result[i].Length - 1);
}
}

return result;
}

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.