Measuring the length of a printed string

J

Jason James

Hi all,

Only when a printpage event is fired from my printdocument
am I able to get a handle on my printer through the passed
parameter as follows

ByVal e As System.Drawing.Printing.PrintPageEventArgs

from e I can obtain the length of the string that will be printed
on my printer by using

StringSize = e.Graphics.MeasureString(string, Font)

This is OK if the printpage event has fired but what if I want to
check whether the string is too long or not before the
printpage event is fired?

Does anybody know of a way of obtaining an object that
contains

System.Drawing.Printing.PrintPageEventArgs

outside of the printpageevent?

Thanks in advance,

Jason.
 
R

Ron Allen

Jason,
You can use CreateMeasurementGraphics on you PrinterSettings object to
get a Graphics with the same metrics as the printer. Use this to measure
your strings.

Ron Allen
 
J

Jason James

Hi Ron,

thanks very much for the information. It took a bit of
sorting out but I finally got everything to work just as
I wanted.

Regards,

Jason.
 

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

Top