PrintSettings2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • VR

    #1

    PrintSettings2

    Also,

    I noticed that PageBounds and PageMargins rectangles are
    not properly representing the page size (or it could be
    the printer). The code below draws a rectangle on the
    screen which isn't really centered, but rather shifted to
    the right of the page:

    private void OnPrintPage
    (
    object sender,
    PrintPageEventA rgs e) float fTop
    )
    {
    float x = e.MarginBounds. Left;
    float y = e.MarginBounds. Top;
    float height = e.MarginBounds. Height;
    float width = e.MarginBounds. Width;

    Pen oPen3 = new Pen(Brushes.Bla ck, 2.0F);
    e.Graphics.Draw Rectangle(oPen3 , x, y, width, height);

    e.HasMorePages = false;
    }


    Also, if I were to do the same with PageBounds rectangle,
    should I be able to see it on the page, or should it be
    drawn right at the very edge of the page?

    When I look at PageBounds in debugger, I see left and top
    set to 0 and width and height are 850 and 1100. I assumed
    that a unit represents 1/100 of an inch, and therefore,
    the rectangle should be right at the edge of the page --
    probably shouldn't even come out.

    But it does come out, and top left corner of the rectangle
    is offset by about a 1/6 inch from top and left sides of
    the page... The right and the bottom of the rectangle
    don't even appear on the page.

    So, I kept printing rectangles until they started
    appearing in full on the page and it seems that it I have
    to offset the right and the bottom sides of rectangle by
    about 30-35 units from the right and the bottom (3/10
    inch?).

    Does anybody have a clue what I am talking about? (I jsut
    re-read what I came up with and I barely understand
    myself:))

    Thanks for any suggestions.

    VR
  • Michael Mayer

    #2
    Re: PrintSettings2

    To start with, the box not being at the edge of the page, is expected. From
    the property "OriginAtMargin s" of the PrintDocument class, it is evident
    that the origin of the graphics object will either be "located just inside
    the user-specified margins or at the top-left corner of the printable area
    of the page". Take note - this is printable area of the page, which is
    different for every printer (new "borderless " inkjets may very well be at
    the very edge of the page, most laserjets need about a half-inch or so at
    top & bottom).

    http://msdn.microsoft.com/library/de...rginstopic.asp

    Trying to center something on the page becomes somewhat of a guessing game,
    if I recall. You have to assume that the printable area of the page is
    centered within the actual page (which may be the case left to right, but
    often is not the case top to bottom). MS seems to have not provided any way
    to get to this piece of the puzzle. Petzold's book C# Windows Programming
    has a really thorough description of the problem. I don't own the book (I
    basically read the important chapters while sitting at a Borders book store)
    and, unfortunately, don't remember if there is a good work-around, or what
    it is.
    http://www.microsoft.com/mspress/books/5188.asp

    I believe there are basically two chapters of concern (whether or not it's
    worth buying the book for those two chapters depends on how desperate you
    are!):
    Pages and transforms
    Printing

    I decided it wasn't something I needed correct for my documents, so I
    stopped researching this. Now, as I think about this, I am getting more
    confused than ever, so I'll just refer you to either Petzold's book (which
    will at least restore some sanity, even if it doesn't give you your full
    solution) and the aid of other ng'ers.

    Good luck!

    --
    Mike Mayer

    mike@mag37.com


    "VR" <Victor.Rozenkr ant@gat.com> wrote in message
    news:068d01c36d e7$7d64b210$a60 1280a@phx.gbl.. .[color=blue]
    > Also,
    >
    > I noticed that PageBounds and PageMargins rectangles are
    > not properly representing the page size (or it could be
    > the printer). The code below draws a rectangle on the
    > screen which isn't really centered, but rather shifted to
    > the right of the page:
    >
    > private void OnPrintPage
    > (
    > object sender,
    > PrintPageEventA rgs e) float fTop
    > )
    > {
    > float x = e.MarginBounds. Left;
    > float y = e.MarginBounds. Top;
    > float height = e.MarginBounds. Height;
    > float width = e.MarginBounds. Width;
    >
    > Pen oPen3 = new Pen(Brushes.Bla ck, 2.0F);
    > e.Graphics.Draw Rectangle(oPen3 , x, y, width, height);
    >
    > e.HasMorePages = false;
    > }
    >
    >
    > Also, if I were to do the same with PageBounds rectangle,
    > should I be able to see it on the page, or should it be
    > drawn right at the very edge of the page?
    >
    > When I look at PageBounds in debugger, I see left and top
    > set to 0 and width and height are 850 and 1100. I assumed
    > that a unit represents 1/100 of an inch, and therefore,
    > the rectangle should be right at the edge of the page --
    > probably shouldn't even come out.
    >
    > But it does come out, and top left corner of the rectangle
    > is offset by about a 1/6 inch from top and left sides of
    > the page... The right and the bottom of the rectangle
    > don't even appear on the page.
    >
    > So, I kept printing rectangles until they started
    > appearing in full on the page and it seems that it I have
    > to offset the right and the bottom sides of rectangle by
    > about 30-35 units from the right and the bottom (3/10
    > inch?).
    >
    > Does anybody have a clue what I am talking about? (I jsut
    > re-read what I came up with and I barely understand
    > myself:))
    >
    > Thanks for any suggestions.
    >
    > VR[/color]


    Comment

    • Ron Allen

      #3
      Re: PrintSettings2

      Michael/Victor,
      The 'solution' on Framework 1.0 is to use PInvoke on GetDeviceCaps and
      retrieve the actual hard printer margins. I've got some code to do this and
      it was also written up in MSDN Magazine several issues ago. Once you have
      the printers hard margins just do a translate on the affected graphics
      object by -left, -top and everything will then work the same as
      PrintPreview. For added complications you may need to look at the overall
      available print width and see if that fits your desired printed area. If it
      is too small then you need to scale the graphics object appropriately. This
      lets you print things on inkjet printers with large hard margins that
      normally are output to laser systems. You may need to do this if your
      printer's printable area is smaller than your margin bounds as well even on
      Framework 1.1.

      Ron Allen
      "Michael Mayer" <mike@mag37.com > wrote in message
      news:OpQHMofbDH A.1280@tk2msftn gp13.phx.gbl...[color=blue]
      > To start with, the box not being at the edge of the page, is expected.[/color]
      From[color=blue]
      > the property "OriginAtMargin s" of the PrintDocument class, it is evident
      > that the origin of the graphics object will either be "located just inside
      > the user-specified margins or at the top-left corner of the printable area
      > of the page". Take note - this is printable area of the page, which is
      > different for every printer (new "borderless " inkjets may very well be at
      > the very edge of the page, most laserjets need about a half-inch or so at
      > top & bottom).
      >
      >[/color]
      http://msdn.microsoft.com/library/de...rginstopic.asp[color=blue]
      >
      > Trying to center something on the page becomes somewhat of a guessing[/color]
      game,[color=blue]
      > if I recall. You have to assume that the printable area of the page is
      > centered within the actual page (which may be the case left to right, but
      > often is not the case top to bottom). MS seems to have not provided any[/color]
      way[color=blue]
      > to get to this piece of the puzzle. Petzold's book C# Windows Programming
      > has a really thorough description of the problem. I don't own the book (I
      > basically read the important chapters while sitting at a Borders book[/color]
      store)[color=blue]
      > and, unfortunately, don't remember if there is a good work-around, or what
      > it is.
      > http://www.microsoft.com/mspress/books/5188.asp
      >
      > I believe there are basically two chapters of concern (whether or not it's
      > worth buying the book for those two chapters depends on how desperate you
      > are!):
      > Pages and transforms
      > Printing
      >
      > I decided it wasn't something I needed correct for my documents, so I
      > stopped researching this. Now, as I think about this, I am getting more
      > confused than ever, so I'll just refer you to either Petzold's book (which
      > will at least restore some sanity, even if it doesn't give you your full
      > solution) and the aid of other ng'ers.
      >
      > Good luck!
      >
      > --
      > Mike Mayer
      > http://www.mag37.com/csharp/
      > mike@mag37.com
      >
      >
      > "VR" <Victor.Rozenkr ant@gat.com> wrote in message
      > news:068d01c36d e7$7d64b210$a60 1280a@phx.gbl.. .[color=green]
      > > Also,
      > >
      > > I noticed that PageBounds and PageMargins rectangles are
      > > not properly representing the page size (or it could be
      > > the printer). The code below draws a rectangle on the
      > > screen which isn't really centered, but rather shifted to
      > > the right of the page:
      > >
      > > private void OnPrintPage
      > > (
      > > object sender,
      > > PrintPageEventA rgs e) float fTop
      > > )
      > > {
      > > float x = e.MarginBounds. Left;
      > > float y = e.MarginBounds. Top;
      > > float height = e.MarginBounds. Height;
      > > float width = e.MarginBounds. Width;
      > >
      > > Pen oPen3 = new Pen(Brushes.Bla ck, 2.0F);
      > > e.Graphics.Draw Rectangle(oPen3 , x, y, width, height);
      > >
      > > e.HasMorePages = false;
      > > }
      > >
      > >
      > > Also, if I were to do the same with PageBounds rectangle,
      > > should I be able to see it on the page, or should it be
      > > drawn right at the very edge of the page?
      > >
      > > When I look at PageBounds in debugger, I see left and top
      > > set to 0 and width and height are 850 and 1100. I assumed
      > > that a unit represents 1/100 of an inch, and therefore,
      > > the rectangle should be right at the edge of the page --
      > > probably shouldn't even come out.
      > >
      > > But it does come out, and top left corner of the rectangle
      > > is offset by about a 1/6 inch from top and left sides of
      > > the page... The right and the bottom of the rectangle
      > > don't even appear on the page.
      > >
      > > So, I kept printing rectangles until they started
      > > appearing in full on the page and it seems that it I have
      > > to offset the right and the bottom sides of rectangle by
      > > about 30-35 units from the right and the bottom (3/10
      > > inch?).
      > >
      > > Does anybody have a clue what I am talking about? (I jsut
      > > re-read what I came up with and I barely understand
      > > myself:))
      > >
      > > Thanks for any suggestions.
      > >
      > > VR[/color]
      >
      >[/color]


      Comment

      Working...