This article was previously published under Q80185
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Some printers support changing the orientation of the paper output tolandscape. With the Windows API Escape() function, you can changethe settings of the printer to either landscape or portrait. In addition,if you have one of the following products, you can use the Common Dialogbox to allow users to set the mode inside a Visual Basic Application:
Visual Basic version 1.0 Professional Toolkit
Professional Edition of Visual Basic version 2.0
Standard or Professional Edition of Visual Basic version 3.0
Below is an example showing how to invoke the Windows API Escape()function from Microsoft Visual Basic.
NOTE: The Windows API Escape() function is provided in Windows versions3.0 and 3.1 for backward compatibility with earlier versions of MicrosoftWindows. Applications are supposed to use the GDI DeviceCapabilities() andExtDeviceMode() functions instead of the Escape() function, but neitherDeviceCapabilities() nor ExtDeviceMode() can be called directly from VisualBasic. This is because they are exported by the printer driver, not by theWindows GDI. The only way to use ExtDeviceMode() or DeviceCapabilities()in Visual Basic is to create a DLL and call them from there.
Normally, output for the printer is in portrait mode, where output isprinted horizontally across the narrower dimension of a paper. Inlandscape mode, the output is printed horizontally across the longerdimension of the paper.
You can use the Escape() function to change the orientation of theprinter by passing GETSETPAPERORIENT as an argument. When youinitially print text to the printer, Visual Basic will use thecurrently selected orientation. Sending the Escape() function will nottake effect until you perform a Printer.EndDoc. After you perform aPrinter.EndDoc, output will print in the orientation that you haveselected.
To determine if your printer supports landscape mode, do thefollowing:
From the Windows Program Manager, run Control Panel.
From the Control Panel, select the Printers icon.
From the Printers dialog box, choose the Configure button.
The Configure dialog box will contain an option for landscape orientation if landscape is supported on your printer.
How to Check the Current Orientation of the Printer
To check the current orientation of the printer, use the following code:
' Enter the following Declare statement as one, single line:
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
How to Change the Printer Orientation to Landscape
The following example below demonstrates how to change the printerorientation to landscape. Please note that your printer must supportlandscape mode for these commands to have any effect.
Start a new project in Visual Basic (ALT, F, N). Form1 is created by default.
Add a command button (Command1) to Form1.
Add the following code to the global module:
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)
Add the following code to the Command1_Click event procedure of the Command1 button:
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