469,619 Members | 1,885 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Landscape printing in vb.net ??

Hello,

I can't seem to get printing to landscape working. Here is some of the code
I've tried.

'---------------------------------------------------------------------------------
Dim myDocument As PrintDocument = PreparePrintDocument()
Dim myPaperSize As PaperSize
Dim iSizeCount As Integer
Dim dlgPrint As New PrintDialog

iSizeCount = 0

' Set to our selected printer
myDocument.PrinterSettings.PrinterName = PrinterList.Text
' This hides the print progress dialog
myDocument.PrintController = New
System.Drawing.Printing.StandardPrintController
' Print Landscape
myDocument.PrinterSettings.DefaultPageSettings.Lan dscape.Equals(True)

For Each myPaperSize In myDocument.PrinterSettings.PaperSizes
If myDocument.PrinterSettings.PaperSizes(iSizeCount). Kind =
PaperKind.Number10Envelope Then
myDocument.DefaultPageSettings.PaperSize =
myDocument.PrinterSettings.PaperSizes(iSizeCount)
Exit For
End If
iSizeCount = iSizeCount + 1
Next

' Ok let's try landscape one more time...
myDocument.DefaultPageSettings.Landscape.Equals(Tr ue)
MsgBox(myDocument.DefaultPageSettings.Landscape.To String)

'dlgPrint.Document = myDocument

'MsgBox(dlgPrint.PrinterSettings.DefaultPageSettin gs.Landscape.ToString)
'dlgPrint.ShowDialog()

'MsgBox(dlgPrint.PrinterSettings.DefaultPageSettin gs.Landscape.ToString)

dlgPrintPreview.Document = myDocument
dlgPrintPreview.ShowDialog()

'Print immediately.
'myDocument.Print(
'---------------------------------------------------------------------------------

The only time I ever get landscape to be active is if I display the
PrintDialog and allow the user to select it. I can't get it to work in code
no matter how many places I set it.

Jul 21 '05 #1
3 10032
Setting of the landscape mode should read like:

myDocument.DefaultPageSettings.Landscape = True

Try that!
"MarcJ" wrote:
Hello,

I can't seem to get printing to landscape working. Here is some of the code
I've tried.

'---------------------------------------------------------------------------------
Dim myDocument As PrintDocument = PreparePrintDocument()
Dim myPaperSize As PaperSize
Dim iSizeCount As Integer
Dim dlgPrint As New PrintDialog

iSizeCount = 0

' Set to our selected printer
myDocument.PrinterSettings.PrinterName = PrinterList.Text
' This hides the print progress dialog
myDocument.PrintController = New
System.Drawing.Printing.StandardPrintController
' Print Landscape
myDocument.PrinterSettings.DefaultPageSettings.Lan dscape.Equals(True)

For Each myPaperSize In myDocument.PrinterSettings.PaperSizes
If myDocument.PrinterSettings.PaperSizes(iSizeCount). Kind =
PaperKind.Number10Envelope Then
myDocument.DefaultPageSettings.PaperSize =
myDocument.PrinterSettings.PaperSizes(iSizeCount)
Exit For
End If
iSizeCount = iSizeCount + 1
Next

' Ok let's try landscape one more time...
myDocument.DefaultPageSettings.Landscape.Equals(Tr ue)
MsgBox(myDocument.DefaultPageSettings.Landscape.To String)

'dlgPrint.Document = myDocument

'MsgBox(dlgPrint.PrinterSettings.DefaultPageSettin gs.Landscape.ToString)
'dlgPrint.ShowDialog()

'MsgBox(dlgPrint.PrinterSettings.DefaultPageSettin gs.Landscape.ToString)

dlgPrintPreview.Document = myDocument
dlgPrintPreview.ShowDialog()

'Print immediately.
'myDocument.Print()
'---------------------------------------------------------------------------------

The only time I ever get landscape to be active is if I display the
PrintDialog and allow the user to select it. I can't get it to work in code
no matter how many places I set it.

Jul 21 '05 #2
That works great! I had tried that initially but must have done something
wrong because it didn't work either.

But riddle me this. Why doesn't
myDocument.PrinterSettings.DefaultPageSettings.Lan dscape.Equals(True) work?
Wouldn't that be the .net way of doing things? If not, what exactly is that
supposed to do??

"Ben Solomon" wrote:
Setting of the landscape mode should read like:

myDocument.DefaultPageSettings.Landscape = True


Jul 21 '05 #3
The statment

myDocument.PrinterSettings.DefaultPageSettings.Lan dscape.Equals(True)

might appear to set the landscape mode but I don't it really does at all.
The rest of the code sample is just fine I believe.

You might want to look up what the Equals method does.
It compiles but it doesn't set landscape mode... That's why
it only worked when the user selected it in the dialog. I believe
it checks if two expressions/objects are "equal"...


"MarcJ" wrote:
That works great! I had tried that initially but must have done something
wrong because it didn't work either.

But riddle me this. Why doesn't
myDocument.PrinterSettings.DefaultPageSettings.Lan dscape.Equals(True) work?
Wouldn't that be the .net way of doing things? If not, what exactly is that
supposed to do??

"Ben Solomon" wrote:
Setting of the landscape mode should read like:

myDocument.DefaultPageSettings.Landscape = True

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by gilga123 | last post: by
reply views Thread by gilga123 | last post: by
2 posts views Thread by Andrei Gavra via .NET 247 | last post: by
5 posts views Thread by cpopham | last post: by
3 posts views Thread by MarcJ | last post: by
1 post views Thread by lord.zoltar | last post: by
6 posts views Thread by sheinaz | last post: by
2 posts views Thread by FireStarter | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.