0

How do I generate a preview in the printdialog box in vb.net. In the frame where the preview would appear, the message "This app doesn't support print preview' appears. (Pictured below)

I use the following code like the examples below to set up my print dialog before the actual printing code. The printing works fine. Searching for the answer to this keeps pointing me to the printpreviewdialog which is not what I'm trying to do.

Private Sub PrintReplacementCostReport(Optional ByVal Title As String = "Replacement Cost Report")

  Dim Caller As String = GetCurrentMethod.DeclaringType.Name & "." & GetCurrentMethod.Name
  'ClsDebug.LogProcEnter(New StackFrame(0, True).GetFileLineNumber, Caller)

  ClearErrorMessage()

  m_PageTitle = "Replacement Cost Report"
  ModGlobals.ReportRichTextBox = Me.rtfReport

  If Me.rtfReport.Lines.Count > 0 Then

     _currentRecord = 1 '-- Skip the heading

     SetPrintDocumentCommonSettings(m_PageTitle)
     SetPrintDialogCommonSettings()

     If PrintDialog1.ShowDialog = DialogResult.OK Then

        ClearErrorMessage()

        PrintDocument1.Print()

     End If

     ClearErrorMessage()

  Else
     If m_PageTitle = "Replacement Cost Report" Then

        Report("You Must Run a [Replacement Cost] Report Before Printing")
     End If
  End If

  'ClsDebug.LogProcExit(New StackFrame(0, True).GetFileLineNumber, Caller)

End Sub

 Private Sub SetPrintDialogCommonSettings(Optional ByVal ToFile As Boolean = False)

  With PrintDialog1
     .Document = PrintDocument1

     .PrinterSettings = PrintDocument1.PrinterSettings

     .AllowSomePages = True
     .AllowSelection = True
     .AllowPrintToFile = True
     .AllowCurrentPage = True

     If ToFile Then
        .PrinterSettings.PrinterName = "Microsoft Print to PDF"
        .PrintToFile = True
        .PrinterSettings.PrintFileName = "PrintDialogToFile.pdf"
     End If
  End With

End Sub

 Private Sub SetPrintDocumentCommonSettings(ByVal Title As String,
                                          Optional ByVal ToFile As Boolean = False,
                                          Optional ByVal ToFileName As String = "")

  With PrintDocument1
     .DocumentName = Title

     .PrinterSettings.Copies = 1
     .PrinterSettings.PrintToFile = True


     .DefaultPageSettings.Margins.Right = 50
     .DefaultPageSettings.Margins.Left = 50
     .DefaultPageSettings.Margins.Top = 50
     .DefaultPageSettings.Margins.Bottom = 50

     If ToFile Then
        .DefaultPageSettings.PrinterSettings.PrintToFile = True
        .DefaultPageSettings.PrinterSettings.PrinterName = "Microsoft Print to PDF"
        .DefaultPageSettings.PrinterSettings.PrintFileName = "Roosevelt Dimes.pdf"

     End If

     .PrinterSettings.DefaultPageSettings.Margins.Left = 30 '50
     .PrinterSettings.DefaultPageSettings.Margins.Right = 30 '50

     .PrinterSettings.DefaultPageSettings.Margins.Top = 50
     .PrinterSettings.DefaultPageSettings.Margins.Bottom = 50

     yPos = .PrinterSettings.DefaultPageSettings.Margins.Top
  End With

  m_RememberSubTitle = String.Empty
  m_RememberTitle = String.Empty
  ModGlobals.WhiteSpace = False

  m_Landscape = False

  _PageChanged = True
  _currentPage = 0

End Sub

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.