Calculating text width when printing

  • Thread starter Thread starter Jack Russell
  • Start date Start date
J

Jack Russell

Any bright ideas on how I can calculate how wide a piece of text will be
when printing.
When writing text to the screen in graphics mode I put it in a invisible
text box to get its height and width (as suggested on this group).
But obviously I cannot do that with the printer.

Thanks
 
Jack Russell said:
Any bright ideas on how I can calculate how wide a piece of text
will be when printing.
When writing text to the screen in graphics mode I put it in a
invisible text box to get its height and width (as suggested on this
group). But obviously I cannot do that with the printer.

Call a graphics object's MeasureString method. In the
PrintDocument.PrintPage event, you get it in e.graphics.
Before printing you get it from
System.Drawing.Printing.PrinterSettings.CreateMeasurementGraphics.

Armin
 
Armin said:
Call a graphics object's MeasureString method. In the
PrintDocument.PrintPage event, you get it in e.graphics.
Before printing you get it from
System.Drawing.Printing.PrinterSettings.CreateMeasurementGraphics.

Armin
But dont' you have to put the string somewhere to measure it. If I put
it on the printer how do I get it off if it is too long (or am I missing
something basic here?).
 
Jack Russell said:
But dont' you have to put the string somewhere to measure it. If I
put it on the printer how do I get it off if it is too long (or am I
missing something basic here?).

You only have to put it in the call to the function. The function returns
the size. Then you can check the size to see whether it's too long.

Armin
 
Armin said:
You only have to put it in the call to the function. The function
returns the size. Then you can check the size to see whether it's too long.

Armin
Thanks,
There is something about .net that makes me miss the obvious!

Jack
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top