Printing using margins

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

    Printing using margins

    I am trying to print a form using the following code, everything works fine
    but the margins are not acted upon. What I am I doing wrong?



    Private Sub CaptureScreen()
    Dim myGraphics As Graphics = Me.CreateGraphi cs()
    Dim s As Size = Me.Size
    memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
    Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
    memoryGraphics. CopyFromScreen( Me.Location.X, Me.Location.Y, 0, 0, s)
    End Sub



    Private Sub printDocument1_ PrintPage(ByVal sender As System.Object, _
    ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles
    printDocument1. PrintPage

    Dim margins As New Margins(0, 0, 600, 0)
    printDocument1. DefaultPageSett ings.Margins = margins
    e.Graphics.Draw Image(memoryIma ge, 0, 0)

    End Sub



  • Ron Allen

    #2
    Re: Printing using margins

    tm,
    You didn't say which version of the framework you are using. For 1.x
    you will need to compensate for the 'hard margins' on the printer by
    PInvoking GetDeviceCaps to get the margins. Also you won't be able to print
    except for inside those margins as the printer isn't capable of printing
    there. Except for some very high end printers most aren't capable of
    printing to the edge of the paper.
    You can look for GetHardMargins in this newsgroup or in
    microsoft.publi c.dotnet.framew ork.drawing to find some code to get the
    actual printer margin values. If you are using FW 2.0 you can use the
    properties of the PrintDocument to find the margins.

    Ron Allen
    "tm" <tbmcl@cwnet.co m> wrote in message
    news:%23OdhplRK GHA.648@TK2MSFT NGP14.phx.gbl.. .[color=blue]
    >I am trying to print a form using the following code, everything works fine
    > but the margins are not acted upon. What I am I doing wrong?
    >
    >
    >
    > Private Sub CaptureScreen()
    > Dim myGraphics As Graphics = Me.CreateGraphi cs()
    > Dim s As Size = Me.Size
    > memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
    > Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
    > memoryGraphics. CopyFromScreen( Me.Location.X, Me.Location.Y, 0, 0,
    > s)
    > End Sub
    >
    >
    >
    > Private Sub printDocument1_ PrintPage(ByVal sender As System.Object, _
    > ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles
    > printDocument1. PrintPage
    >
    > Dim margins As New Margins(0, 0, 600, 0)
    > printDocument1. DefaultPageSett ings.Margins = margins
    > e.Graphics.Draw Image(memoryIma ge, 0, 0)
    >
    > End Sub
    >
    >
    >[/color]


    Comment

    • tm

      #3
      Re: Printing using margins

      Ron,

      I am using Framework 2.0

      I have tried searching "GetHardMar gins " with no luck.
      If I add the following to my sub printDocument1_ PrintPage
      I do see my margins settings, but this just proves that I can
      set and read back the PageSetupDialog 1 information. It
      seems that the info is not getting back to the printer.
      What ties the PageSetupDialog to the system default printer?

      With PageSetupDialog 1

      Dim leftMargin As Single = .PageSettings.M argins.Left

      Dim rightMargin As Single = .PageSettings.M argins.Right

      Dim topMargin As Single = .PageSettings.M argins.Top

      Dim BottomMargin As Single = .PageSettings.M argins.Bottom

      End With



      tom


      Comment

      • Dennis

        #4
        Re: Printing using margins

        You can get the printable page size from the PrintPageEventA rgs.PageBounds
        which is passed to the PrintPage Event.


        --
        Dennis in Houston


        "tm" wrote:
        [color=blue]
        > Ron,
        >
        > I am using Framework 2.0
        >
        > I have tried searching "GetHardMar gins " with no luck.
        > If I add the following to my sub printDocument1_ PrintPage
        > I do see my margins settings, but this just proves that I can
        > set and read back the PageSetupDialog 1 information. It
        > seems that the info is not getting back to the printer.
        > What ties the PageSetupDialog to the system default printer?
        >
        > With PageSetupDialog 1
        >
        > Dim leftMargin As Single = .PageSettings.M argins.Left
        >
        > Dim rightMargin As Single = .PageSettings.M argins.Right
        >
        > Dim topMargin As Single = .PageSettings.M argins.Top
        >
        > Dim BottomMargin As Single = .PageSettings.M argins.Bottom
        >
        > End With
        >
        >
        >
        > tom
        >
        >
        >[/color]

        Comment

        • tm

          #5
          Re: Printing using margins

          Dennis,

          I capture the image in the CaptureScreen sub.

          What I want to do is use Margins to begin printing
          6 inches down from the top. But the default printer
          seems not to see the new margins I set in the
          printDocument1 event and continus to print
          at the top.

          If you have any suggestions of what I am doing
          wrong I would appreciate your feed back.

          tom


          Private Sub CaptureScreen()
          Dim myGraphics As Graphics = Me.CreateGraphi cs()
          Dim s As Size = Me.Size
          memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
          Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
          memoryGraphics. CopyFromScreen( Me.Location.X, Me.Location.Y, 0, 0, s)
          End Sub


          Private Sub printDocument1_ PrintPage(ByVal sender As System.Object, _
          ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles _
          printDocument1. PrintPage

          Dim margins As New Margins(0, 0, 600, 0)
          printDocument1. DefaultPageSett ings.Margins = margins
          e.Graphics.Draw Image(memoryIma ge, 0, 0)

          End Sub


          Comment

          • Dennis

            #6
            Re: Printing using margins

            You are drawing to the page graphics object and you need to use the point for
            the drawing to start. If you want the drawing to be 6 inches from the top of
            the paper and 2 inches from the left side of the paper, use

            e.Graphics.Draw Image(memoryIma ge, 200, 600).

            The margins have nothing to do with it.


            --
            Dennis in Houston


            "tm" wrote:
            [color=blue]
            > Dennis,
            >
            > I capture the image in the CaptureScreen sub.
            >
            > What I want to do is use Margins to begin printing
            > 6 inches down from the top. But the default printer
            > seems not to see the new margins I set in the
            > printDocument1 event and continus to print
            > at the top.
            >
            > If you have any suggestions of what I am doing
            > wrong I would appreciate your feed back.
            >
            > tom
            >
            >
            > Private Sub CaptureScreen()
            > Dim myGraphics As Graphics = Me.CreateGraphi cs()
            > Dim s As Size = Me.Size
            > memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
            > Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
            > memoryGraphics. CopyFromScreen( Me.Location.X, Me.Location.Y, 0, 0, s)
            > End Sub
            >
            >
            > Private Sub printDocument1_ PrintPage(ByVal sender As System.Object, _
            > ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles _
            > printDocument1. PrintPage
            >
            > Dim margins As New Margins(0, 0, 600, 0)
            > printDocument1. DefaultPageSett ings.Margins = margins
            > e.Graphics.Draw Image(memoryIma ge, 0, 0)
            >
            > End Sub
            >
            >
            >[/color]

            Comment

            • tm

              #7
              Re: Printing using margins

              Thanks Dennis, I have been working on this for a week.

              Now that I can print at the bottom I have another question,
              is it possible to do two CaptureScreen() and send one two
              print at the top and the other to print at the bottom.

              Or prevent the form feed from ejecting the paper which would
              allow printing on top then print at bottom then eject the paper.

              tom





              "Dennis" <Dennis@discuss ions.microsoft. com> wrote in message
              news:50DCC4F3-180C-44BC-8577-D0D71ACEA898@mi crosoft.com...[color=blue]
              > You are drawing to the page graphics object and you need to use the point
              > for
              > the drawing to start. If you want the drawing to be 6 inches from the top
              > of
              > the paper and 2 inches from the left side of the paper, use
              >
              > e.Graphics.Draw Image(memoryIma ge, 200, 600).
              >
              > The margins have nothing to do with it.
              >
              >
              > --
              > Dennis in Houston
              >
              >
              > "tm" wrote:
              >[color=green]
              >> Dennis,
              >>
              >> I capture the image in the CaptureScreen sub.
              >>
              >> What I want to do is use Margins to begin printing
              >> 6 inches down from the top. But the default printer
              >> seems not to see the new margins I set in the
              >> printDocument1 event and continus to print
              >> at the top.
              >>
              >> If you have any suggestions of what I am doing
              >> wrong I would appreciate your feed back.
              >>
              >> tom
              >>
              >>
              >> Private Sub CaptureScreen()
              >> Dim myGraphics As Graphics = Me.CreateGraphi cs()
              >> Dim s As Size = Me.Size
              >> memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
              >> Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
              >> memoryGraphics. CopyFromScreen( Me.Location.X, Me.Location.Y, 0, 0,
              >> s)
              >> End Sub
              >>
              >>
              >> Private Sub printDocument1_ PrintPage(ByVal sender As System.Object, _
              >> ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles _
              >> printDocument1. PrintPage
              >>
              >> Dim margins As New Margins(0, 0, 600, 0)
              >> printDocument1. DefaultPageSett ings.Margins = margins
              >> e.Graphics.Draw Image(memoryIma ge, 0, 0)
              >>
              >> End Sub
              >>
              >>
              >>[/color][/color]


              Comment

              • Dennis

                #8
                Re: Printing using margins

                You can print as many images as you want wherever you want, even overlapping
                so long as you do it before exiting the routine. If you want to change
                pages, just set the PrintPageEventA rgs.HasMorePage s = True and the PrintPages
                sub will be called again. You can use a static variable in the sub to keep
                track of which page you are on.

                Dennis in Houston


                "tm" wrote:
                [color=blue]
                > Thanks Dennis, I have been working on this for a week.
                >
                > Now that I can print at the bottom I have another question,
                > is it possible to do two CaptureScreen() and send one two
                > print at the top and the other to print at the bottom.
                >
                > Or prevent the form feed from ejecting the paper which would
                > allow printing on top then print at bottom then eject the paper.
                >
                > tom
                >
                >
                >
                >
                >
                > "Dennis" <Dennis@discuss ions.microsoft. com> wrote in message
                > news:50DCC4F3-180C-44BC-8577-D0D71ACEA898@mi crosoft.com...[color=green]
                > > You are drawing to the page graphics object and you need to use the point
                > > for
                > > the drawing to start. If you want the drawing to be 6 inches from the top
                > > of
                > > the paper and 2 inches from the left side of the paper, use
                > >
                > > e.Graphics.Draw Image(memoryIma ge, 200, 600).
                > >
                > > The margins have nothing to do with it.
                > >
                > >
                > > --
                > > Dennis in Houston
                > >
                > >
                > > "tm" wrote:
                > >[color=darkred]
                > >> Dennis,
                > >>
                > >> I capture the image in the CaptureScreen sub.
                > >>
                > >> What I want to do is use Margins to begin printing
                > >> 6 inches down from the top. But the default printer
                > >> seems not to see the new margins I set in the
                > >> printDocument1 event and continus to print
                > >> at the top.
                > >>
                > >> If you have any suggestions of what I am doing
                > >> wrong I would appreciate your feed back.
                > >>
                > >> tom
                > >>
                > >>
                > >> Private Sub CaptureScreen()
                > >> Dim myGraphics As Graphics = Me.CreateGraphi cs()
                > >> Dim s As Size = Me.Size
                > >> memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
                > >> Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
                > >> memoryGraphics. CopyFromScreen( Me.Location.X, Me.Location.Y, 0, 0,
                > >> s)
                > >> End Sub
                > >>
                > >>
                > >> Private Sub printDocument1_ PrintPage(ByVal sender As System.Object, _
                > >> ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles _
                > >> printDocument1. PrintPage
                > >>
                > >> Dim margins As New Margins(0, 0, 600, 0)
                > >> printDocument1. DefaultPageSett ings.Margins = margins
                > >> e.Graphics.Draw Image(memoryIma ge, 0, 0)
                > >>
                > >> End Sub
                > >>
                > >>
                > >>[/color][/color]
                >
                >
                >[/color]

                Comment

                Working...