Re: Word Wrap while Printing

From: Ron Allen (rallen_at__nospam_src-us.com)
Date: 02/17/05


Date: Thu, 17 Feb 2005 09:26:22 -0500

Jeff,
    To get the # of lines used for the wrapped printing you can use the
MeasureString method that takes a SizeF argument (#7 of 7 in my Intellisense
list). The SizeF should be the width and height of the rectangle you are
printing in and, of course, use the same StringFormat as the DrawString
call. This overload has two out parameters nline, and nchars that return
the # of lines and characters that fit. If nchars is less than the length
of the string the string would be truncated on output. You can use this to
see if remaining text fits on the rest of the page and then advance the
baseline by the # of lines returned after you draw the string.

Ron Allen
"Jeff B." <jsb@community.nospam> wrote in message
news:eEksTeJFFHA.2540@TK2MSFTNGP09.phx.gbl...
> Thanks Kevin and Picho for the info. You both understood exactly what I
> was after and the "rectangle" method you mention almost does exactly what
> I need. The only part I'm missing is being able to increment the line
> count by how many lines the text was wrapped so the subsequent lines
> display correctly and the pages break correctly.
>
> I think I'm going to take a slightly different approach and break the
> lines out programmatically as I print them. I'll post back any
> successes - or failures :-)
>
> --- Jeff
>
> --
>
> Jeff Bramwell
> Digerati Technologies, LLC
> www.digeratitech.com
>
> Manage Multiple Network Configurations with Select-a-Net
> www.select-a-net.com
>
> "Jeff B." <jsb@community.nospam> wrote in message
> news:OWA0Te9EFHA.560@TK2MSFTNGP15.phx.gbl...
>> 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 PrintPage event of a
>> PrintDocument object) to send some formatted text to the printer.
>> However, if the lines are too long they run off the page rather than
>> wrapping around. I'm sure I can spend the time and come up with a word
>> wrapping algorithm but figured why go through the trouble if someone
>> already knows of one :-)
>>
>> --- Thanks, Jeff
>>
>> --
>>
>> Jeff Bramwell
>> Digerati Technologies, LLC
>> www.digeratitech.com
>>
>> Manage Multiple Network Configurations with Select-a-Net
>> www.select-a-net.com
>>
>>
>
>



Relevant Pages

  • Re: printing on the right side of paper
    ... and print the string as it provided better measurement for this. ... default StringFormat used in MeasureString some padding around the string ... You will also need to consider printer hard margins when printing as 0,0 ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Print current selected record to a report
    ... Ok, I got it printing out the current record ok now, but it won't print out ... Dim stDocName As String ... DoCmd.OpenReport "rptFinancialAssesment",,, strWhere ...
    (microsoft.public.access.formscoding)
  • Re: printing variable problems
    ... Marco van de Voort said ... printing a string that is prefixed with a given number of space ... characters, does not always start at the same position? ...
    (comp.lang.pascal.borland)
  • Re: Probably simple problem with networking
    ... printing over 300 blank characters, ... You may want to truncate your string to the ...
    (microsoft.public.dotnet.languages.csharp)