使用printform组件选择页面的打印机和设置边距

时间:2015-07-01 19:44:50

标签: vb.net printform

如何添加打印机选择对话框,以及如何控制页面的边距? 我在代码中尝试了很多东西(printdocument代码可以工作但是它们没有显示我的表单)但是它们没有用。我正在使用此代码打印表单:

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

Me.Close()

它正在工作但是,它没有要求打印机选择,我无法控制边距。

由于

1 个答案:

答案 0 :(得分:0)

我终于找到了解决方案,现在是:

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

非常感谢。