Glen Gibb
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
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
what are you using to print?
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(Curre ntReport.C ategoryFK)
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
Private Overloads Sub OnPrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles MyBase.PrintPage
mPageNumber += 1
Dim cat As TestCategory = TestCategory.GetById(Curre
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.Printer Name = ListBox1.SelectedItem
' Set the page orientation to landscape.
pd.DefaultPageSettings.Lan dscape = True
pd.Print()
Dim pd As New PrintDocument
AddHandler pd.PrintPage, AddressOf pd_PrintPage
' Specify the printer to use
pd.PrinterSettings.Printer
' Set the page orientation to landscape.
pd.DefaultPageSettings.Lan
pd.Print()
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.DefaultPageS ettings property. To specify settings on a page-by-page basis, handle the PrintDocument.PrintPage or PrintDocument.QueryPageSet tings 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
"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.DefaultPageS
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
ASKER
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
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