Search code examples
vb.netvisual-studiovisual-studio-2010printingprintform

Printing Form in Landscape using PrintForm Function


i have a question i am trying print the form in landscape so it can print all of the content of the form.

Here is the print preview look like it is cut.

enter image description here

I am using this code to print it and also use the landscape mode to true i search in 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

But it has the same result. Thank you.


Solution

  • I did this along time ago from something I found on a Google search. It will give you a printersettings dialog where you can select landscape before printing. If memory serves, the Printform.PrinterSettings.DefaultPageSettings.Landscape is read only or has an issue. Can't remember, anyway, you will need to add a PageSetupDialog and a PrintDocument to the form. Then change your code to this:

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

    When you click your button1, you should be prompted with a page setup dialog where you can select landscape. Click OK and your form should print landscape.

    I Guess if you don't want the Page Setup dialog, you could just have it print by setting the PageSetupDialog1's settings to Landscape.

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