Home All Groups Group Topic Archive Search About

Calculating text width when printing

Author
28 Jun 2005 8:45 AM
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

Author
28 Jun 2005 8:51 AM
Armin Zingler
"Jack Russell" <ja***@norubbish.tpg.com.au> schrieb
> 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
Author
28 Jun 2005 9:51 AM
Jack Russell
Armin Zingler wrote:
Show quoteHide quote
> "Jack Russell" <ja***@norubbish.tpg.com.au> schrieb
>
>> 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
>
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?).
Author
28 Jun 2005 10:03 AM
Armin Zingler
Show quote Hide quote
"Jack Russell" <ja***@norubbish.tpg.com.au> schrieb
> Armin Zingler wrote:
> > "Jack Russell" <ja***@norubbish.tpg.com.au> schrieb
> >
> > > 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
> >
> 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
Author
28 Jun 2005 11:23 AM
Jack Russell
Armin Zingler wrote:
Show quoteHide quote
> "Jack Russell" <ja***@norubbish.tpg.com.au> schrieb
>
>> Armin Zingler wrote:
>> > "Jack Russell" <ja***@norubbish.tpg.com.au> schrieb
>> >
>> > > 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
>> >
>> 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
>
Thanks,
There is something about .net that makes me miss the obvious!

Jack