472,143 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

printing on the right side of paper

Friends,

I'm (a bit) dissapointed about the printing possibilities in c#. It could
also be lack of knowedge.

I would like to align a text on the right side of the paper when printing.

For example
tekst = DateTime.Today.Date.ToString("dd-MM-yyyy");
// asign content to the variable tekst
SizeF stringSize= ev.Graphics.MeasureString(tekst, printFont);
// measure the length of the tekst ... in what??
xPos = (float) ev.MarginBounds.Right - stringSize;
// to aligh it on thr right side of the paper
ev.Graphics.DrawString (tekst, printFont, Brushes.Black, xPos, yPos, new
StringFormat());

I would like to print tekst now but I have problems with the typing.

I tried all kinds of things but there must be some easy way of doing this.
Who can help me with this..

and who knows a bunch of nice printing functions. I dont like the way C#
handles the printer control.

regards
Gerrit Esmeijer


Nov 16 '05 #1
1 2372
See microsoft.public.dotnet.framework.drawing for many discussions on
drawing/printing things.

That said, you want to use a StringFormat.GenericTypographic to measure
and print the string as it provided better measurement for this. The
default StringFormat used in MeasureString some padding around the string
when measuring it. MeasureString returns values in the units selected for
the current Graphics.
You will also need to consider printer hard margins when printing as 0,0
starts at the top/left of the printable area by default. Using Framework
1.1 you can set OriginAtMargins to true and then 0,0 will be at the
intersection of your left and top margins.
I basically wrote my own set of printing utilities to do my printing so
that I have methods to align a string at a point including left and center
aligning. This was a rewrite of the utilities I've been using ever since I
was writing Postscript code to draw custom forms on the early Apple
Laserwriters.
If you actually want to get the printer's hard margins and printable
extent I have some C# routines that you can have.

Ron Allen
"G.Esmeijer" <ge****@nomail.nl> wrote in message
news:41**********************@dreader2.news.tiscal i.nl...
Friends,

I'm (a bit) dissapointed about the printing possibilities in c#. It could
also be lack of knowedge.

I would like to align a text on the right side of the paper when printing.

For example
tekst = DateTime.Today.Date.ToString("dd-MM-yyyy");
// asign content to the variable tekst
SizeF stringSize= ev.Graphics.MeasureString(tekst, printFont);
// measure the length of the tekst ... in what??
xPos = (float) ev.MarginBounds.Right - stringSize;
// to aligh it on thr right side of the paper
ev.Graphics.DrawString (tekst, printFont, Brushes.Black, xPos, yPos, new
StringFormat());

I would like to print tekst now but I have problems with the typing.

I tried all kinds of things but there must be some easy way of doing this.
Who can help me with this..

and who knows a bunch of nice printing functions. I dont like the way C#
handles the printer control.

regards
Gerrit Esmeijer

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by mykidisgollum | last post: by
4 posts views Thread by Rajani | last post: by
reply views Thread by Niyazi | last post: by
2 posts views Thread by Jurjen de Groot | last post: by
3 posts views Thread by D Witherspoon | last post: by
7 posts views Thread by tm | last post: by
1 post views Thread by Anne DeBlois | last post: by
8 posts views Thread by Frank Rizzo | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.