Selecting printer and settings margins of page wit

2019-09-05 11:49发布

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条回答
够拽才男人
2楼-- · 2019-09-05 12:07

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.

查看更多
登录 后发表回答