Link to home
Start Free TrialLog in
Avatar of Glen Gibb
Glen GibbFlag for Canada

asked on

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?

Capt
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

what are you using to print?
Avatar of Glen Gibb

ASKER

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
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
pd.Print()

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'?

Capt
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

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

Capt