• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 497
  • Last Modified:

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 Gibb
Glen Gibb
  • 4
  • 3
1 Solution
É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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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.
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now