printing on the right side of paper

G

G.Esmeijer

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
 
R

Ron Allen

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
 

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