473,382 Members | 1,733 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,382 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 10546
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.