By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Measuring the length of a printed string

P: n/a
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.
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
"Jason James" <ja***@jamesjl.demon.co.uk> wrote in message
news:rm********************************@4ax.com...
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.

Nov 20 '05 #2

P: n/a
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.

On Wed, 21 Jan 2004 09:27:18 -0500, "Ron Allen"
<rallen@_nospam_src-us.com> wrote:
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
"Jason James" <ja***@jamesjl.demon.co.uk> wrote in message
news:rm********************************@4ax.com.. .
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.


Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.