Selecting printer and settings margins of page with printform component

試著忘記壹切 提交于 2019-12-12 00:15:41

问题


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:


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.



来源:https://stackoverflow.com/questions/31170331/selecting-printer-and-settings-margins-of-page-with-printform-component

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!