none
How to print a report using the ReportDocument? RRS feed

  • Question

  • Please I need your help.

    This is my first time using the ReportDocument component to print a report.

    I need to print a report on a prepared form that has special size of (height 24 cm, width 18.6 cm). The report must show the print dialog first to give the user the option to select a printer if the required printer is not the default printer. The report must be printed right away without any page preview.

    I read some documentation on how to use the ReportDocument component and I started creating the required report after I did all the measurements of the prepared form regarding the size, height, width and margins.

    Now my I’m facing the following problems.

    1.     Converting the centimeters to inch when the measurement in units of 1/100 inch.

    2.     How I can set the page size and page margins.

    Thank you.

    Public Sub PrintReport()
        mpdReport = New PrintDocument
        Dim newMargins As System.Drawing.Printing.Margins
        newMargins = New System.Drawing.Printing.Margins(CInt(0.2), CInt(0.4), CInt(1.1), CInt(0.5))
    
        With mpdReport
          .DefaultPageSettings.Margins = newMargins
        End With
    
        With mpdPrintDialog
          .AllowPrintToFile = False
          .AllowSomePages = False
          .AllowSelection = False
          .ShowHelp = False
          .ShowNetwork = False
    
          .Document = mpdReport
          If .ShowDialog() = DialogResult.OK Then
            mpdReport.Print()
          End If
        End With
      End Sub

    • Edited by Sami2020 Friday, July 9, 2010 12:16 PM Codes
    • Moved by Ji.Zhou Monday, July 12, 2010 6:21 AM (From:Visual Basic General)
    Friday, July 9, 2010 11:58 AM

All replies

  •  

     

    Public Sub PrintReport()
        mpdReport = New PrintDocument
        Dim newMargins As System.Drawing.Printing.Margins
        newMargins = New System.Drawing.Printing.Margins(CInt(0.2), CInt(0.4), CInt(1.1), CInt(0.5))
    
        With mpdReport
          .DefaultPageSettings.Margins = newMargins
        End With
    
        With mpdPrintDialog
          .AllowPrintToFile = False
          .AllowSomePages = False
          .AllowSelection = False
          .ShowHelp = False
          .ShowNetwork = False
    
          .Document = mpdReport
          If .ShowDialog() = DialogResult.OK Then
            mpdReport.Print()
          End If
        End With
      End Sub

    Friday, July 9, 2010 12:18 PM
  • Hello Sami,

    The question is Visual Studio Report Control related, so I am moving it to the right place for you to get better responses,

    http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/threads

    Have a nice day!

     

    Best regards,
    Ji Zhou - MSFT
    Microsoft Online Community Support


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Monday, July 12, 2010 6:23 AM
  • I have posted a sample that shows how to print using a PrintDocument: http://blogs.msdn.com/b/brianhartman/archive/2009/02/27/manually-printing-a-report.aspx
    • Proposed as answer by Ji.Zhou Wednesday, July 14, 2010 3:07 AM
    Monday, July 12, 2010 3:45 PM
    Moderator
  • Please I only need to know how can I set the page size (24cm H, 18.6 cm W)? How can I convert the  centimeters to inch when the measurement in units of 1/100 inch used in the DotNet?

    Thank you.

    Thursday, July 15, 2010 2:33 PM