Selecting printer and settings margins of page with printform component

5.5k Views Asked by At

How can I add printer selection dialog, and how can I control margins of a page? I tried so many things in code (printdocument codes works but they don't show my form) but they did not work. I'm using this code to print form:

With Me.PrintForm1
    .PrintAction = Printing.PrintAction.PrintToPreview
    .Print(Me, PowerPacks.Printing.PrintForm.PrintOption.ClientAreaOnly)
End With

Me.Close()

It's working but, it does not asks for printer selection and I can't control margins.

Thanks

1

There are 1 best solutions below

1
On BEST ANSWER

I found the solution finally, here it is:

PrintDialog1.PrinterSettings = PrintForm1.PrinterSettings
    PrintDialog1.AllowSomePages = True
    If PrintDialog1.ShowDialog = DialogResult.OK Then
        PrintForm1.PrinterSettings = PrintDialog1.PrinterSettings

        With Me.PrintForm1
            .PrintAction = Printing.PrintAction.PrintToPreview



            Dim MyMargins As New Margins

            With MyMargins
                .Left = 40
                .Right = 40
                .Top = 40
                .Bottom = 40
            End With

            .PrinterSettings.DefaultPageSettings.Margins = MyMargins

            PrintForm1.DocumentName = notasyon_lbl.Text
            .Print(Me, PowerPacks.Printing.PrintForm.PrintOption.CompatibleModeClientAreaOnly)

        End With

    End If

Thanks anyway.