skip to Main Content

I am trying to print an envelope. I can do this on different size envelopes. So printing is not the problem.

What is the problem is that the print preview (from windows, not the vb.net object) is not showing the preview. Here is the code I have thus far:

Private Sub btn_PrintEnvelope_Click(sender As Object, e As EventArgs) Handles btn_PrintEnvelope.Click
        Dim PageSetup As New PageSettings

        If cb_EnvelopeSize.SelectedIndex <> -1 Then
            Select Case cb_EnvelopeSize.SelectedIndex
                Case 0  '~~ #10 Envlope
                    With PageSetup
                        .Margins.Left = 218
                        .Margins.Right = 253
                        .Margins.Top = 0
                        .Margins.Bottom = 100
                        .Landscape = False
                    End With
                Case 1  '~~ 6x9 Envelope
                    With PageSetup
                        .Margins.Left = 125
                        .Margins.Right = 160
                        .Margins.Top = 0
                        .Margins.Bottom = 200
                        .Landscape = False
                    End With
                Case 2  '~~ A7 Envelope
                    With PageSetup
                        .Margins.Left = 163
                        .Margins.Right = 198
                        .Margins.Top = 5
                        .Margins.Bottom = 415
                        .Landscape = False
                    End With
            End Select

            PrintDoc.DefaultPageSettings = PageSetup
            PrintDoc.DocumentName = "Client Envelope"

            PrintDialog.ShowHelp = True

            PrintDialog.Document = PrintDoc

            If PrintDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
                PrintDoc.Print()
            End If
        End If
    End Sub

and this is what I get on the preview:

The Print Preview Dialog

From all the documentation I have read, this should work. But when I put a break on the code inside the PrintDoc_PrintPage, it does not stop until I select print on window’s print preview.

Any ideas what I am doing wrong or what I am I missing?

I’ve tried to add the print preview dialog control from vb.net, but then I get an old fashioned print preview (which does show the envelope) and then when I select print, I get the above one. So there is no need for two previews, but I would like that one to work.

I am using Visual Studio 2022 (64-bit) version 17.5.4.

2

Answers


  1. Chosen as BEST ANSWER

    No, I stated that I am not using the PrintPreview control for a number of reasons.

    1. It is archaic in looks
    2. The posted print preview comes up anyway when printing. Why have a print preview twice?

    And for the pdf selection, I am printing out envelopes from a database. If I had to do that for each and every one (upwards to 200 a day) that would be very slow.

    The shown preview is from WINDOWS itself and caused by the call to PrintDoc which is a PrintDocument control.

    Hope that helps.

    P.S. It even seems the PrintDoc.DocumentName does not appear in the caption as I thought it would.


  2. Use PrintPreviewDialog:

    Using ppvPreview As New PrintPreviewDialog
      ppvPreview.Document = PrintDoc
      ppvPreview.FindForm.WindowState = FormWindowState.Maximized
      If IsNothing(Owner) Then
        ppvPreview.ShowDialog()
      Else
        ppvPreview.ShowDialog(Owner)
      End If
    End Using
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search