Landscape mode not happening

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?

Glen GibbOwnerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
what are you using to print?
Glen GibbOwnerAuthor Commented:
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
Éric MoreauSenior .Net ConsultantCommented:
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

Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Glen GibbOwnerAuthor Commented:
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'?

Éric MoreauSenior .Net ConsultantCommented:
once the job is started, I don't think you can change the orientation.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Glen GibbOwnerAuthor Commented:
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.

Glen GibbOwnerAuthor Commented:
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.