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

Is there a wrapping routine in the .NET Framework??

P: n/a
Siv
Hi,
I am trying to find a wrapping routine for text and not having much luck.
The reason I need one is that I am producing a report where the text that
was stored in the database was written into a multi-line text box, so it
contains long strings of text where the user allowed the wrapping of the
text box to wrap the text within its confines and here and there, they will
have entered CRLFs where they have pressed ENTER to push in a break between
paragraphs. This has always caused me problems when writing this stuff out
to a report as I have a certain width on the printed page and usually a
certain amount of depth. There must be a .NET framework function that can
process a piece of text and insert the relevant breaks that doesn't split
words and constrains it within a given rectangle that you specify.

Can anyone help me as I can't find anything??
--
Siv
Martley, Near Worcester, United Kingdom.
Apr 1 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Siv,

You don't get word for free, but what you ask looks for me the most at the
RichTextBox.

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor

"Siv" <dotnet@remove_me.sivill.com> schreef in bericht
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,
I am trying to find a wrapping routine for text and not having much luck.
The reason I need one is that I am producing a report where the text that
was stored in the database was written into a multi-line text box, so it
contains long strings of text where the user allowed the wrapping of the
text box to wrap the text within its confines and here and there, they
will have entered CRLFs where they have pressed ENTER to push in a break
between paragraphs. This has always caused me problems when writing this
stuff out to a report as I have a certain width on the printed page and
usually a certain amount of depth. There must be a .NET framework
function that can process a piece of text and insert the relevant breaks
that doesn't split words and constrains it within a given rectangle that
you specify.

Can anyone help me as I can't find anything??
--
Siv
Martley, Near Worcester, United Kingdom.

Apr 1 '06 #2

P: n/a
Hi Siv,
There must be a .NET framework function that can
process a piece of text and insert the relevant breaks that doesn't split
words and constrains it within a given rectangle that you specify.


No, there is no such pre-built function in .NET. You're going have to
code for such a functionality.

This thread asks a question that, I believe, is related to what you
want to do. Check it out and see if it helps,

<http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/34ec19dee644b0db>

Regards,

Cerebrus.

Apr 1 '06 #3

P: n/a
Siv
Cor,

I think you may have misunderstood what I am after. I am writing a report
that the user can priny out. The data that I am trying to display in the
report is made up of long strings of text. I then have to write that out to
a printed report but I have to fit it into a rectangular box on that report
that has a certain width and depth.

My problem comes in trying to get that text wrapped to fit the report layout
without losing any of the text or breaking words up as well as honouring any
carriage returns that were entered in the original piece of text.

As a lot of controls like the rich text box and the multi-line text box
intelligently wrap text as you type, there must be a routine (presumably
part of the Dot Net Framwork) that these controls use and I was hopeful I
could use that in my printing routine.

I have tried to roll my own and got a fairly good routine but it seems a bit
sluggish and it sometimes gets confused stuck in an iterative loop that I
haven't been able to fix yet, due to deadlines I decided I would see if
there was a built in function that does the same job, returning the text
formatted with line breaks that allow it to fit on the report within the
specified widths.
--
Siv
Martley, Near Worcester, United Kingdom.
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Ov*************@TK2MSFTNGP11.phx.gbl...
Siv,

You don't get word for free, but what you ask looks for me the most at the
RichTextBox.

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor

"Siv" <dotnet@remove_me.sivill.com> schreef in bericht
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,
I am trying to find a wrapping routine for text and not having much luck.
The reason I need one is that I am producing a report where the text that
was stored in the database was written into a multi-line text box, so it
contains long strings of text where the user allowed the wrapping of the
text box to wrap the text within its confines and here and there, they
will have entered CRLFs where they have pressed ENTER to push in a break
between paragraphs. This has always caused me problems when writing this
stuff out to a report as I have a certain width on the printed page and
usually a certain amount of depth. There must be a .NET framework
function that can process a piece of text and insert the relevant breaks
that doesn't split words and constrains it within a given rectangle that
you specify.

Can anyone help me as I can't find anything??
--
Siv
Martley, Near Worcester, United Kingdom.


Apr 1 '06 #4

P: n/a
Siv
Cerebrus,

I am pleased to say that you are wrong (I don't mean that in a nasty way),
after hunting around furiously in the MSDN documentation I found the
answer!! Hurrah. The routine I currently use to output the text actually
does it, I just hadn't looked at the overloaded versions of the drawstring
method.

The code that does the magic is:

Dim rect As System.Drawing.RectangleF
Dim str as String

Str = sp.TaskMMDetails 'A piece of text from a class with lots of text
in it with breaks etc.
rect.X = LM + 100 'LM is a var holding my left margin so my
rectangle
rect.Y = y + (n * 100) 'y is a var tracking where I am down the
document incremented by lineheight
rect.Width = LM + 650 'width of my reports rectangle
rect.Height = 100 'Height of my reports rectangle

'Then write it out
e.Graphics.DrawString(Str, fb, Brushes.Black, rect)

The text is output to the report and is wrapped within the rectangle
specified by rect, it works brilliantly.

Additionally there is an additional parameter which deals with string
fromatting which I haven't unravelled yet that allows you to do stuff like
centre align right align etc also there are switches that allow you to
determine whether you want the text that would be cut off by the bottom of
the rectangle to appear or not and also whether it would insrt an elipsis at
the botytom right corner of the rectangle followed by the last word in the
text.

BRILLIANT! Cheers MS it was right under my nose all the time. Teach me to
explore all the overloaded versions.

For anyone interested the article that led me to this on MSDN is as follows:
http://msdn.microsoft.com/library/de...ntwinforms.asp

Thanks to Cor for putting me in the MSDN library which prompted me to look a
bit harder and find the answer there.
Thanks to Cerberus for responding, I was getting a bit despondent as a
couple of my questions here earlier seemed to be sitting unanswered.
--
Siv
Martley, Near Worcester, United Kingdom.

"Cerebrus" <zo*****@sify.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
Hi Siv,
There must be a .NET framework function that can
process a piece of text and insert the relevant breaks that doesn't
split
words and constrains it within a given rectangle that you specify.


No, there is no such pre-built function in .NET. You're going have to
code for such a functionality.

This thread asks a question that, I believe, is related to what you
want to do. Check it out and see if it helps,

<http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/34ec19dee644b0db>

Regards,

Cerebrus.

Apr 1 '06 #5

P: n/a
Siv wrote:
BRILLIANT! Cheers MS it was right under my nose all the time. Teach me to
explore all the overloaded versions.


I've noticed that the documentation in MSDN for VS 2005 is vastly
improved for this sort of thing wrt what came before.

:-)

Yeah, MS, that was a compliment! It's good to see a steady improvement
and the new docs now lack only an index into fundamentals documents. Or
the fundamentals documents themselves.

Dr. Gui ought to return with a screaming ten-million-dollar-a-year
vengeance, until the core technologies of the 2.0 Framework are fully
explained.

Rob
Apr 1 '06 #6

P: n/a
"Siv" <dotnet@remove_me.sivill.com> schrieb:
I am trying to find a wrapping routine for text and not having much luck.
The reason I need one is that I am producing a report where the text that
was stored in the database was written into a multi-line text box, so it
contains long strings of text where the user allowed the wrapping of the
text box to wrap the text within its confines and here and there, they
will have entered CRLFs where they have pressed ENTER to push in a break
between paragraphs. This has always caused me problems when writing this
stuff out to a report as I have a certain width on the printed page and
usually a certain amount of depth. There must be a .NET framework
function that can process a piece of text and insert the relevant breaks
that doesn't split words and constrains it within a given rectangle that
you specify.


Check out the overloads of 'Graphics.DrawString' if you want to draw text
with word wrapping turned on.

Additional topics:

Determining the lines as they are being displayed in a textbox control
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=textboxdisplayedlines&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Apr 1 '06 #7

P: n/a
Siv
Rob,

I must confess to being a bit useless with search help, I can search for
hours and not find what I want and other people just seem to instinctively
know what to enter in the search engine to get what they want. It was the
same in exams as a kid, all the kids would read the question and get the
correct meaning, I would read it and assume it was a lot more complicated
than it was. I think my brain must be in backwards?
--
Siv
Martley, Near Worcester, United Kingdom.

"Rob Perkins" <rp******@usa.net> wrote in message
news:49************@individual.net...
Siv wrote:
BRILLIANT! Cheers MS it was right under my nose all the time. Teach me
to explore all the overloaded versions.


I've noticed that the documentation in MSDN for VS 2005 is vastly improved
for this sort of thing wrt what came before.

:-)

Yeah, MS, that was a compliment! It's good to see a steady improvement and
the new docs now lack only an index into fundamentals documents. Or the
fundamentals documents themselves.

Dr. Gui ought to return with a screaming ten-million-dollar-a-year
vengeance, until the core technologies of the 2.0 Framework are fully
explained.

Rob

Apr 1 '06 #8

P: n/a
Siv
Herfried,
Thanks, I already found this myself if you check out the other replies to
this question, but thanks anyway as I might not have.

--
Siv
Martley, Near Worcester, United Kingdom.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uT**************@TK2MSFTNGP10.phx.gbl...
"Siv" <dotnet@remove_me.sivill.com> schrieb:
I am trying to find a wrapping routine for text and not having much luck.
The reason I need one is that I am producing a report where the text that
was stored in the database was written into a multi-line text box, so it
contains long strings of text where the user allowed the wrapping of the
text box to wrap the text within its confines and here and there, they
will have entered CRLFs where they have pressed ENTER to push in a break
between paragraphs. This has always caused me problems when writing this
stuff out to a report as I have a certain width on the printed page and
usually a certain amount of depth. There must be a .NET framework
function that can process a piece of text and insert the relevant breaks
that doesn't split words and constrains it within a given rectangle that
you specify.


Check out the overloads of 'Graphics.DrawString' if you want to draw text
with word wrapping turned on.

Additional topics:

Determining the lines as they are being displayed in a textbox control
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=textboxdisplayedlines&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Apr 2 '06 #9

P: n/a
Hi Siv,
I am pleased to say that you are wrong (I don't mean that in a nasty way),
after hunting around furiously in the MSDN documentation I found the
answer!!


Thank you very much for that correction. I was thinking in a linear
fashion only(String class members only). A good reminder to me, to
expand my horizon and to "Never say die!".

I'm very glad you found the answer. I will keep it in mind, in case I
need it in the future.

Regards,

Cerebrus.

Apr 2 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.