VB3 How to Set Landscape or Portrait for Printer from VB AppID: Q80185
|
Some printers support changing the orientation of the paper output to
landscape. With the Windows API Escape() function, you can change
the settings of the printer to either landscape or portrait. In addition,
if you have one of the following products, you can use the Common Dialog
box to allow users to set the mode inside a Visual Basic Application:
Normally, output for the printer is in portrait mode, where output is
printed horizontally across the narrower dimension of a paper. In
landscape mode, the output is printed horizontally across the longer
dimension of the paper.
You can use the Escape() function to change the orientation of the
printer by passing GETSETPAPERORIENT as an argument. When you
initially print text to the printer, Visual Basic will use the
currently selected orientation. Sending the Escape() function will not
take effect until you perform a Printer.EndDoc. After you perform a
Printer.EndDoc, output will print in the orientation that you have
selected.
To determine if your printer supports landscape mode, do the
following:
Declare Function Escape% Lib "GDI" (ByVal hDC%, ByVal nEsc%, ByVal nLen%,
lpData As Any, lpOut As Any)
Sub Command1_Click ()
Const PORTRAIT = 1
Const LANDSCAPE = 2
Const GETSETPAPERORIENT = 30
Dim Orient As OrientStructure
Printer.Print ""
Orient.Orientation = LANDSCAPE
x% = Escape(Printer.hDC, GETSETPAPERORIENT, Len(Orient), "", Null)
Print x%
End Sub
Type OrientStructure
Orientation As Long
Pad As String * 16
End Type
' Enter the following Declare statement on one, single line:
Declare Function Escape% Lib "GDI" (ByVal hDc%, ByVal nEsc%,
ByVal nLen%, lpData As OrientStructure, lpOut As Any)
Sub Command1_Click ()
Const PORTRAIT = 1
Const LANDSCAPE = 2
Const GETSETPAPERORIENT = 30
Dim Orient As OrientStructure
'* Start the printer
Printer.Print ""
'* Specify the orientation
Orient.Orientation = LANDSCAPE
'* Send escape sequence to change orientation
x% = Escape(Printer.hDC, GETSETPAPERORIENT,
Len(Orient), Orient, NULL)
'* The EndDoc will now re-initialize the printer
Printer.EndDoc
Printer.Print "Should print in landscape mode"
Printer.EndDoc
End Sub
Additional query words: 2.00 3.00 vb3only
Keywords : kbcode kbPrinting
Version : WINDOWS:1.0,2.0,3.0
Platform : WINDOWS
Issue type :
Last Reviewed: May 19, 1999