Changing from Portrait to Landscape PrintDocument/PrintPreview

6.6k views Asked by At

I've been reading reams of documentation about PrintPreviewDialog, PrintPreviewControl and PrintDocument. Everything says that I have to put the Portrait/Lanscape bit into the PrintDocument QueryPageSettings Event, then the PrintPreviewDialog will get the settings from the PrintDocument.

I started off with:

    Private Sub PrintDocument1_QueryPageSettings(ByVal sender As Object, ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs) Handles PrintDocument1.QueryPageSettings
    Select Case mOrientation
        Case ePrinterOrientation.Landscape
            PrintDocument1.DefaultPageSettings.Landscape = True
        Case ePrinterOrientation.Portrait
            PrintDocument1.DefaultPageSettings.Landscape = False
    End Select
End Sub

Here's my current code

   Private Sub PrintDocument1_QueryPageSettings(ByVal sender As Object, ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs) Handles PrintDocument1.QueryPageSettings
    Select Case mOrientation
        Case ePrinterOrientation.Landscape
            Dim ps As New PaperSize("A4Landscape", 1169, 827)
            ps.PaperName = PaperKind.A4
            PrintDocument1.DefaultPageSettings.PaperSize = ps
            PrintDocument1.DefaultPageSettings.Landscape = True
        Case ePrinterOrientation.Portrait
            Dim ps As New PaperSize("A4Portrait", 827, 1169)
            ps.PaperName = PaperKind.A4
            PrintDocument1.DefaultPageSettings.PaperSize = ps
            PrintDocument1.DefaultPageSettings.Landscape = False
    End Select
End Sub

I also tried putting this code into the PrintDocument1_BeginPrint event, this did change the "Window" of the PrintPreview, but the contents of the PrintDocument still stayed Portrait (the width of the used "view", remain the same).

The Portrait mode spans the 10 columns over 2 pages, the Landscape mode should have all the columns on 1 page, but this is not the case, the "PrintableArea" margins appear to remain exactly the same in reality, even if the numbers change to the correct values if I step through debug.

I'm getting truely p****d off with this, this 3-way dependency, it should be simpler than this.

Edit:

Further to this problem. If I PRINT the document, the orientation is set to Landscape, but the Print Margins (the Document) is still printed (with overflow) as though the margins are Portrait.

I REALLY need to fix this. It is NOT acceptable.

2

There are 2 answers

0
coder148747 On
PaperSize("A4Landscape", 1169, 827)

should be

PaperSize("A4Landscape", 827, 1169)

Same goes to Portrait.

0
Luc Bogman On

Instead of

PrintDocument1.DefaultPageSettings.Landscape = True

Use

e.PageSettings.Landscape = True

What you are trying to do is change the values of the Event within PrintDoc1_QueryPageSettings:

System.Drawing.Printing.QueryPageSettingsEventArgs