C# Printing Problem

  • Thread starter Thread starter Dane
  • Start date Start date
D

Dane

I am having a problem printing in C#. I am using DrawString() with
the RectagleF class to determine the location to print. I am doing it
this way so that I can get the text to auto wrap.

The problem I am having is this: Is there any way to make the
rectangle grow based on the contents or a way to determine exactly
what the height should be so I do not lose text when printing? The
data I am printing will contain line breaks so I cannot use a fuction
that will simply tell me how long the string is based on the font
size.

Any ideas anyone?

Dane
 
The problem I am having is this: Is there any way to make the
rectangle grow based on the contents or a way to determine exactly
what the height should be so I do not lose text when printing? The
data I am printing will contain line breaks so I cannot use a fuction
that will simply tell me how long the string is based on the font
size.

If you know the maximum width of the area you wish to print in, then you can
use the Graphics.MeasureString function because that can take in an optional
max width. If you do not know the max width, then One can only assume that
it's actually 1 line per line break, in which you can simply read the number
of line breaks and then you will know how many lines you have, and can
measure the height appropriately by measuring one line and multiplying by
the total number of lines.

-akshay
 
Dane,
Use the overload of MeasureString that returns the #of lines fitted to a
SizeF area and make the SizeF for this the correct width and tall enough to
avoid overflow. You will get back the # of lines fitted. This overload
returns both # of characters and # of lines fitted.

Ron Allen
 
Back
Top