Printing in landscape mode

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I tried posting earlier and it never showed up..

I have a simple program to print a text file. I need to know how to change the page settings to landscape if it is not already in ladnscape mode. I do not want to use a dialog to do it and this appears the only way you can do it. I just need it to spit out the print in landscape orientation. Why is this so hard to do for something that should be easy.
 
* "=?Utf-8?B?Y3BvcGhhbQ==?= said:
I have a simple program to print a text file. I need to know how to
change the page settings to landscape if it is not already in ladnscape
mode. I do not want to use a dialog to do it and this appears the only
way you can do it. I just need it to spit out the print in landscape
orientation. Why is this so hard to do for something that should be
easy.

Sample taken from MSDN documentation:

\\\
Public Sub Printing()
Try
streamToPrint = New StreamReader(filePath)
Try
printFont = New Font("Arial", 10)
Dim pd As New PrintDocument()
AddHandler pd.PrintPage, AddressOf pd_PrintPage
pd.PrinterSettings.PrinterName = printer
' Set the page orientation to landscape.
pd.DefaultPageSettings.Landscape = True
pd.Print()
Finally
streamToPrint.Close()
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
///
 
Try this line

PrintDoc.DefaultPageSettings.Landscape = True

HTH

Les Smith

http://www.KnowDotNet.com

Articles, add-ins, free code.



cpopham said:
I tried posting earlier and it never showed up...

I have a simple program to print a text file. I need to know how to
change the page settings to landscape if it is not already in ladnscape
mode. I do not want to use a dialog to do it and this appears the only way
you can do it. I just need it to spit out the print in landscape
orientation. Why is this so hard to do for something that should be easy.
 
* "=?Utf-8?B?Y3BvcGhhbQ==?= said:
PrintDocument.DefaultPageSettings.Landscape = True

I have tried that in several different ways and it compiles fine, but
it does not change the page settings from portrait to landscape. It is
as if the DefaultPageSettings are just there for you to check the page
settings.

I have not tested it, but try to set the orientation before the
'PrintPage' handler is called for the page.
 
You need to call this code before you start the printing process. i.e.,
before the PrintPage event gets called.
Les]

cpopham said:
That one part:

PrintDocument.DefaultPageSettings.Landscape = True

I have tried that in several different ways and it compiles fine, but it
does not change the page settings from portrait to landscape. It is as if
the DefaultPageSettings are just there for you to check the page settings.
 
Add a handler for OnQueryPageSettings and set the Landscape property there.
Quick ex.
Private Sub
AuditorPrintDocument_OnQueryPageSettings(QueryPageSettingsEventArgs e)
base.OnQueryPageSettings(e)
e.PageSettings.Landscape = True
End Sub

Ron Allen
cpopham said:
That one part:

PrintDocument.DefaultPageSettings.Landscape = True

I have tried that in several different ways and it compiles fine, but it
does not change the page settings from portrait to landscape. It is as if
the DefaultPageSettings are just there for you to check the page settings.
 
Back
Top