473,383 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 10547
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: gilga123 | last post by:
Trying & trying ad infinitum to print page in landscape mode from Java program - orientation is correct landscape but printing width will NOT go to landscape - always prints in portrait mode width...
0
by: gilga123 | last post by:
Trying & trying ad infinitum to print page in landscape mode from Java program - orientation is correct landscape but printing width will NOT go to landscape - always prints in portrait mode width...
2
by: Andrei Gavra via .NET 247 | last post by:
Hello. I have a problem when I choose landscape format forprinting. The page width and height are remaining the same asfor portrait format. In portrait format everything is ok and I'mposition my text...
5
by: cpopham | last post by:
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. ...
3
by: MarcJ | last post by:
Hello, I can't seem to get printing to landscape working. Here is some of the code I've tried. '--------------------------------------------------------------------------------- Dim...
1
by: lord.zoltar | last post by:
Hi, I'm trying to print a text report from an application. It works fine, except in landscape mode, which it seems to ignore. I have a function that handles the PrintPage even for the...
6
by: sheinaz | last post by:
Hi I am tryign to use this to print my table in landscape by default. i am new at the xsl and need some assistance. when i try to use the following i get the error: Cannot view XML input using...
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...
6
by: farukcse | last post by:
Dear sir, I have trouble with printing page with landscape. I am using java script to print the page. as well as I have set css file to print landscape but it is not working. I have used these...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.