Printing Question

  • Thread starter Thread starter S Shulman
  • Start date Start date
S

S Shulman

Hi

I know I can use the GetHeight of the Font object to figure out how many
lines will fit into a page, but how can I find out how many characters will
fit into a line

Thank you,
S. Shulman
 
For a fixed-width font, ex. Courier New, you can get the width of a letter
and check that against your margin area. For a proportional font the only
way I know would be to keep adding words to a string and then check the
width using MeasureString. If you just want to wrap paragraphs into an area
you can use a DrawString overload that takes a rectangle to print in. You
can use a MeasureString overload with the same rectangle to get back the #
of lines generated in the rectangle and the # of characters used from the
string. Then draw the string if everything fits and advance your start
point by the # of lines returned.
All this is a bit oversimplified but it will work for simple text
fitting. For more information you should probably look in
microsoft.public.dotnet.framework.drawing.

Ron Allen
 
Thank you

Shmuel

Ron Allen said:
For a fixed-width font, ex. Courier New, you can get the width of a letter
and check that against your margin area. For a proportional font the only
way I know would be to keep adding words to a string and then check the
width using MeasureString. If you just want to wrap paragraphs into an
area you can use a DrawString overload that takes a rectangle to print in.
You can use a MeasureString overload with the same rectangle to get back
the # of lines generated in the rectangle and the # of characters used
from the string. Then draw the string if everything fits and advance your
start point by the # of lines returned.
All this is a bit oversimplified but it will work for simple text
fitting. For more information you should probably look in
microsoft.public.dotnet.framework.drawing.

Ron Allen
 
Back
Top