Landscape mode not happening

Posted on 2005-04-05
Last Modified: 2008-02-01
Can anyone help me get a report to print in Landscape Mode?  (Using Windows Form, not ASP.)

I need to determine what category of data has been passed to the print routine, and dynamically switch the page orientation.

Setting "e.PageSettings.Landscape = true" has no effect.

What am I missing?

Question by:Glen Gibb
    LVL 69

    Expert Comment

    by:Éric Moreau
    what are you using to print?

    Author Comment

    by:Glen Gibb
    Here's the routine.

    Private Overloads Sub OnPrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles MyBase.PrintPage

    mPageNumber += 1

    Dim cat As TestCategory = TestCategory.GetById(CurrentReport.CategoryFK)
    Select Case cat.CatKey
    Case "M", "S"
          e.PageSettings.Landscape = True
    Case Else
          e.PageSettings.Landscape = False
    End Select

    ' create ReportPageEventArgs object ...
    Dim page As New ReportPageEventArgs(e, mPageNumber, mFont, mBrush, mFooterLines)

    ' if we're generating page 1 raise the ReportBegin event
    If mPageNumber = 1 Then
      RaiseEvent ReportBegin(Me, page)
    End If

    ' generate the page header/body/footer
     Select Case ReportType
       Case "Lab Slips"
          RaiseEvent PrintLabSlipDocument(Me, page)
       Case "Report"
          RaiseEvent PrintReportDocument(Me, page)
    End Select

    ' if there are no more pages to generate then raise the ReportEnd event
    If Not page.HasMorePages Then
          RaiseEvent ReportEnd(Me, page)
    End If

    ' restore page values to the underlying PrintPageEventArgs object
    e.Cancel = page.Cancel
    e.HasMorePages = page.HasMorePages

    End Sub
    LVL 69

    Expert Comment

    by:Éric Moreau
    try something like this:

    Dim pd As New PrintDocument
    AddHandler pd.PrintPage, AddressOf pd_PrintPage
    ' Specify the printer to use
    pd.PrinterSettings.PrinterName = ListBox1.SelectedItem
    ' Set the page orientation to landscape.
    pd.DefaultPageSettings.Landscape = True


    Author Comment

    by:Glen Gibb
    This approach does work.  If I set the "defaultpagesettings" property before calling the above routine, the orientation does move to landscape.

    On the other hand, my routine is inside a printdocument class.  Is there no way it can respond to the type of data and change the orientation of the page 'on the fly'?

    LVL 69

    Accepted Solution

    once the job is started, I don't think you can change the orientation.

    Author Comment

    by:Glen Gibb
    MSDN's remarks on PageSettings class seems to suggest that it's at least possible.  (If I read this correctly.)

    "This class is used to specify settings that modify the way a page will be printed. Typically, you set default settings for all pages to be printed through the PrintDocument.DefaultPageSettings property. To specify settings on a page-by-page basis, handle the PrintDocument.PrintPage or PrintDocument.QueryPageSettings event and modify the PageSettings argument included in the PrintPageEventArgs or QueryPageSettingsEventArgs, respectively."

    However, setting the PrintPageEventArgs  "Landscape = true" doesn't seem to be cutting the mustard.

    It would sure simplify things if I could "specify settings on a page-by-page basis," however.


    Author Comment

    by:Glen Gibb
    The answer lies in the "QueryPageSettings" event of the print document.

    You can change PageSettings at this point.  After that, it seems that you're committed.

    Although the question wasn't answered directly, it made me hunt thru MSDN more carefully.  Tnx.


    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now