473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

TextBox WordWrap and Lines Property

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
1 3271
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: lawrence | last post by:
When users enter urls or other long strings it can destroy the formatting of a page. A long url, posted in a comment, can cause page distortions that make the page unreadable, till the website...
4
by: Kerem Gümrükcü | last post by:
Hi, i am about to burst!!! how can i make my string break inside a textbox? i mean with a control charater like "\n", but it does not work! i have a string and i must set the wrap manuall, not...
0
by: Mike | last post by:
Hi All, I mistakenly just posted this to the VB group. Sorry for the cross-post. I am working with a textbox in C# which pulls a set of lines (stored in the database as text_type,...
2
by: Mike | last post by:
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...
22
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't...
3
by: HDB | last post by:
Ok. I have a windows form with a textbox for displaying certain messages. Multiline=true and wordwrap=true. I want to know the amount of the lines currently showing. That should not be any...
6
by: Steve | last post by:
Hi all, Is it possible to force a multiline textbox to insert a hard cr/lf when wordwrapping ?? What I would like is to get a string array from the textbox representing exactly how the text...
1
by: Shawn | last post by:
Anybody know how to use wordwrap=true and multiline = true on a textbox, but still have the textbox.lines attribute advance if the wordwrap happens? I have a large textbox that is setup like this...
1
by: Developer | last post by:
VC++ 2005 Express Edition: I have a textBox with the properties: this->m_TextBox_Desc->Multiline = true; this->m_TextBox_Desc->WordWrap = true; this->m_TextBox_Desc->ScrollBars =...
6
by: =?Utf-8?B?SGFucyAtIERpYUdyYXBoSVQgLQ==?= | last post by:
Hi! sorry for a dumb question. I have a textbox where multiline=true and I want to set the scrolbar from none to vertical when the textbox have more then f.ex. 5 lines, or reverse. How can...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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,...

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.