Landscape printing in vb.net ??

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

Guest

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.Landscape.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(True)
MsgBox(myDocument.DefaultPageSettings.Landscape.ToString)

'dlgPrint.Document = myDocument

'MsgBox(dlgPrint.PrinterSettings.DefaultPageSettings.Landscape.ToString)
'dlgPrint.ShowDialog()

'MsgBox(dlgPrint.PrinterSettings.DefaultPageSettings.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.
 
Setting of the landscape mode should read like:

myDocument.DefaultPageSettings.Landscape = True

Try that!
 
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.Landscape.Equals(True) work?
Wouldn't that be the .net way of doing things? If not, what exactly is that
supposed to do??
 
The statment

myDocument.PrinterSettings.DefaultPageSettings.Landscape.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"...
 
Back
Top