468,491 Members | 1,961 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

Printing in landscape mode

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.
Nov 20 '05 #1
5 6124
* "=?Utf-8?B?Y3BvcGhhbQ==?=" <an*******@discussions.microsoft.com> scripsit:
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
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Try this line

PrintDoc.DefaultPageSettings.Landscape = True

HTH

Les Smith

http://www.KnowDotNet.com

Articles, add-ins, free code.

"cpopham" <an*******@discussions.microsoft.com> wrote in message
news:E1**********************************@microsof t.com...
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.
Nov 20 '05 #3
* "=?Utf-8?B?Y3BvcGhhbQ==?=" <an*******@discussions.microsoft.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
You need to call this code before you start the printing process. i.e.,
before the PrintPage event gets called.
Les]

"cpopham" <an*******@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
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.
I am using version 2003, I do not know if that makes a difference.

This is my code so far:

Private Sub AuditorPrintDocument_PrintPage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) _ Handles AuditorPrintDocument.PrintPage

Dim R As Rectangle
Dim PicW, PicH, PicL, PicT As Integer

With AuditorPrintDocument.DefaultPageSettings
.Landscape = True
End With

PicW = Me.SizePictureBox.Width
PicH = Me.SizePictureBox.Height

With AuditorPrintDocument.DefaultPageSettings.PaperSize
PicL = (.Width - PicW) / 2 - 30
End With

PicT = 20

R = New Rectangle(PicL, PicT, PicW, PicH)
e.Graphics.DrawImage(SizePictureBox.Image, R)

End Sub

Nov 20 '05 #5
Add a handler for OnQueryPageSettings and set the Landscape property there.
Quick ex.
Private Sub
AuditorPrintDocument_OnQueryPageSettings(QueryPage SettingsEventArgs e)
base.OnQueryPageSettings(e)
e.PageSettings.Landscape = True
End Sub

Ron Allen
"cpopham" <an*******@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
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.
I am using version 2003, I do not know if that makes a difference.

This is my code so far:

Private Sub AuditorPrintDocument_PrintPage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) _ Handles AuditorPrintDocument.PrintPage

Dim R As Rectangle
Dim PicW, PicH, PicL, PicT As Integer

With AuditorPrintDocument.DefaultPageSettings
.Landscape = True
End With

PicW = Me.SizePictureBox.Width
PicH = Me.SizePictureBox.Height

With AuditorPrintDocument.DefaultPageSettings.PaperSize
PicL = (.Width - PicW) / 2 - 30
End With

PicT = 20

R = New Rectangle(PicL, PicT, PicW, PicH)
e.Graphics.DrawImage(SizePictureBox.Image, R)

End Sub

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by BlueSky | last post: by
1 post views Thread by nuhura01 | last post: by
2 posts views Thread by FireStarter | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.