Re: printing on the right side of paper

From: Ron Allen (rallen_at__nospam_src-us.com)
Date: 07/29/04


Date: Thu, 29 Jul 2004 09:01:46 -0400

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" <gerrit@nomail.nl> wrote in message
news:41080d9c$0$62379$5fc3050@dreader2.news.tiscali.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
>
>
>
>



Relevant Pages

  • Re: Graphics.MeasureString? or Graphics.DrawString?
    ... but meanwhile I'm trying to figure out why the simplest form of MeasureString didn't already work that way. ... transform done on the graphics being used the size of the string depends on the location. ... What kind of transform is being applied by default, and/or what is the default starting point used by the simplest version of MeasureString? ... A few days ago I settled on a workaround of just adding 4 to the width returned by MeasureString, so the entire legend appears in both XP and Vista. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Graphics.MeasureString? or Graphics.DrawString?
    ... It looks like MeasureString is pretty much useless in Vista. ... Measure String only lost the last 1 character of each legend, ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Word Wrap while Printing
    ... To get the # of lines used for the wrapped printing you can use the ... MeasureString method that takes a SizeF argument (#7 of 7 in my Intellisense ... printing in and, of course, use the same StringFormat as the DrawString ... of the string the string would be truncated on output. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [STRING] retrieve the pixel length, MeasureString
    ... You need an instance of a Graphics object. ... But it seems that the MeasureString method is not available on Asp.Net. ... However, it's not very useful in an ASP.NET application, as you are measuring the string for the screen on the server, and it's displayed in the browser on the client. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Graphics.MeasureString too short
    ... MeasureString has some usable overloads that may help you. ... The MeasureString method is designed for use with individual strings and includes a small amount of extra space before and after the ... display a string narrower than reported by MeasureString. ...
    (microsoft.public.dotnet.languages.csharp)