|Print a form in any orientation|
|By: Microsoft Corporation Date: 11/01/2001|
The PrintForm method creates its own Device Context and therefore ignores any Printer object settings. It will just use
the default orientation of the current default printer.
Because you cannot change how PrintForm behaves, you must print another way. The process described here uses two PictureBoxes, each one covering the Form. This same technique can be used to print any group of controls or a form that is too large for the screen or the page. This example basically prints the controls contained in the PictureBox.
|Private Declare Function
SendMessage Lib "user32" Alias
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4&
Private Const PRF_CHILDREN = &H10&
Private Const PRF_OWNED = &H20&
To print all the controls contained in Picture1, use the following code:
|Dim rv As Long
Picture2.AutoRedraw = True
rv = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hDC, 0)
rv = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hDC, _
PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
Picture2.Picture = Picture2.Image
Picture2.AutoRedraw = False
Printer.Orientation = vbPRORLandscape
Printer.PaintPicture Picture2.Picture, 0, 0
Printer.CurrentY = Picture2.Height + 200
In this case, landscape orientation is used. Change the Printer.Orientation line for portrait orientation.
|Visual Basic Programming Zone is a website by
Lorenzo Dalla Vecchia.
To contact the Webmaster, click here.
Hosted by InWind: www.inwind.it