472,961 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,961 software developers and data experts.

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 6737
* "=?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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: BlueSky | last post by:
Hi, I want to print in Landscape format from an aspx page (when ever the user chooses print from the browser or a print button on the form). I load aspx controls dynamically on the page. I used...
1
by: nuhura01 | last post by:
I want a printing properties to be set to landscape mode, so that when the user click a print button, it will print in landscape mode automatically. I use this code in the code-behind of the web...
2
by: FireStarter | last post by:
I am apparently unable to print landscape... maybe I'm doing something wrong here. I am adding a printDocument to a form. The form also has a textbox containing the text that I want to print and...
4
by: Deano | last post by:
I'm in the situation of having to print a form - not a report. This will fit nicely in a landscape format but by default it prints portrait. Is there any code to make it play nice?
4
by: sarn555 | last post by:
Dear, I want to print a VB6 form in landscape orientation and it should be done in a running mode. I mean through coding everything must be done at runtime. By default, the Form.PrintForm method...
1
Ali Rizwan
by: Ali Rizwan | last post by:
Hi all, How can print data report in landscape mode./ Thanx >> ALI <<
2
by: chpadmamca | last post by:
Below is my html code, is there any way to print this document in landscape mode wih CSS? <html><head><style type="text/css"> table.fixed {table-layout:fixed; width:100%; border-collapse:...
2
Claus Mygind
by: Claus Mygind | last post by:
For my intranet web app we use exclusively FireFox as our browser. I have a report I want to format in the landscape mode and would like to include that code in the print button I display for the...
2
by: dhivyavasya | last post by:
I have to print a web page in landscape mode automatically when print is given. i dont want to go to settings and change the mode manually each time. help is needed
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.