使用 PrintForm 函数横向打印表格

Printing Form in Landscape using PrintForm Function

我有一个问题,我正在尝试横向打印表单,以便它可以打印表单的所有内容。

这是裁切后的打印预览。

我正在使用此代码打印它,并且在 google.

中搜索时也使用横向模式为真
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.PrintForm1.PrinterSettings.DefaultPageSettings.Landscape = True
    Me.PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
    Me.PrintForm1.Print()
End Sub

但是结果是一样的。 谢谢。

我很久以前就在 Google 搜索中发现了一些东西。它会给你一个打印机设置对话框,你可以在打印前 select 横向。如果没记错,Printform.PrinterSettings.DefaultPageSettings.Landscape 是只读的或有问题。不记得了,反正你需要在窗体中添加一个 PageSetupDialog 和一个 PrintDocument。然后将您的代码更改为:

    PageSetupDialog1.Document = PrintDocument1
    If PageSetupDialog1.ShowDialog = DialogResult.OK Then
        PrintForm1.PrinterSettings = PageSetupDialog1.PrinterSettings
        If PrintForm1.PrinterSettings.IsValid Then
            PrintForm1.Print()
        End If
    End If

当您单击 button1 时,系统会提示您出现一个页面设置对话框,您可以在其中 select 横向。单击“确定”,您的表单应横向打印。

我想如果您不想要页面设置对话框,您可以通过将 PageSetupDialog1 的设置设置为横向来打印它。

    PageSetupDialog1.Document = PrintDocument1
    PageSetupDialog1.PrinterSettings.DefaultPageSettings.Landscape = True
    PrintForm1.PrinterSettings = PageSetupDialog1.PrinterSettings
    If PrintForm1.PrinterSettings.IsValid Then
        PrintForm1.Print()
    End If