locked
How to set Margins using the PrintDocument RRS feed

  • Question

  • I have a report that prints but I would like to allow the user to set the margins.  The problem I'm having is I can not figure out how this is supposed to work.  I have this code:

       Private Sub rotHCReport_BeginPrint(ByVal sender As Object, _
              ByVal e As System.Drawing.Printing.PrintEventArgs) Handles Me.BeginPrint
    
            Me.OriginAtMargins = True
            Me.DefaultPageSettings.Margins = New Margins(20, 20, 23, 23)
    
        End Sub
    

    and

      Private Sub rotHCReport_PrintPage(ByVal sender As Object, _
            ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles Me.PrintPage
    
         
            e.Graphics.PageUnit = GraphicsUnit.Inch
            'Print routine follows
     
      End Sub
    

    I actually run through PrintPage twicw to count the pages so I can print "page 1 of 12"

    This will produce the following output:

    good output

    If I try to set the margins to 1/4 of an inch by sending 25, 25, 25, 25 in the Margins constructor nothing prints.  The reason nothing prints is because the margins are being set to some out of range value.  If I change to code to

        Private Sub rotHCReport_BeginPrint(ByVal sender As Object, _
              ByVal e As System.Drawing.Printing.PrintEventArgs) Handles Me.BeginPrint
    
            Me.OriginAtMargins = True
            Me.DefaultPageSettings.Margins = New Margins(21, 20, 23, 23)
    
        End Sub

    Which, according to the documentation, should increase the left margin by 1/100 th of an inch.  But this is what I get:

    bad output

    Can somebody tell me how I can use the margins?  Or do I have to hard code them and tell people thats all that the software allows?

    Thanks

    Thursday, September 7, 2017 2:00 PM

All replies

  • I tried switching to millimeters and received sensible results.  I will report a bug using inches.
    Friday, September 8, 2017 6:40 PM
  • Hi MarDude,

    Thanks for your sharing. Please close this thread via marking the solution as answer. This will make answer searching easier in the forum and be beneficial to community members.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, September 11, 2017 5:58 AM