ID: 425
Viewed: 3449
Added: Aug 19, 2002
Version:
Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo
Thank you for your vote. Please wait...
It appears you already voted for this snippet
It appears your vote value was empty
Example of Using a PictureBox to Print a Form in Any
Orientation
1.Create a new Standard EXE Project. Form1 is created by default.
2.Add two PictureBoxes to Form1 so that each nearly covers the Form.
NOTE: Avoid drawing the second PictureBox within the first. Doing so makes the second PictureBox a member of the first. A simple way to avoid the problem is to place the origin point of the second PictureBox to the left of the origin point of the first PictureBox. Once the second box is drawn, you can resize it so that it is the same size as the first PictureBox.
3.Right-mouse click on Picture2 and choose "Send to Back."
4.Place Picture1 on top of Picture2, covering Picture2.
5.Add a CommandButton and some other controls to Picture1, leaving Picture2 empty.
6.Place this code in the Declarations Section of the module of the Form:
7.Run the Project and click on the "Print Form" button. Note that when you click on Command1, "Print Form", it will print the PictureBox and the controls it contains in Landscape orientation.
Orientation
1.Create a new Standard EXE Project. Form1 is created by default.
2.Add two PictureBoxes to Form1 so that each nearly covers the Form.
NOTE: Avoid drawing the second PictureBox within the first. Doing so makes the second PictureBox a member of the first. A simple way to avoid the problem is to place the origin point of the second PictureBox to the left of the origin point of the first PictureBox. Once the second box is drawn, you can resize it so that it is the same size as the first PictureBox.
3.Right-mouse click on Picture2 and choose "Send to Back."
4.Place Picture1 on top of Picture2, covering Picture2.
5.Add a CommandButton and some other controls to Picture1, leaving Picture2 empty.
6.Place this code in the Declarations Section of the module of the Form:
7.Run the Project and click on the "Print Form" button. Note that when you click on Command1, "Print Form", it will print the PictureBox and the controls it contains in Landscape orientation.
Highlight all by clicking in box
<!---Declaration--->
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& ' Draw the window's client area
Private Const PRF_CHILDREN = &H10& ' Draw all visible child windows
Private Const PRF_OWNED = &H20& ' Draw all owned windows
Highlight All
<!---Code--->
Private Sub Command1_Click()
Dim rv As Long
Picture1.SetFocus ' So that the button doesn't look pressed
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 ' 2
Printer.Print ""
Printer.PaintPicture Picture2.Picture, 0, 0
Printer.CurrentY = Picture2.Height + 200 ' get below image
Printer.Print "Text on the same page as the image!"
Printer.EndDoc
Command1.SetFocus ' Return Focus
End Sub
Private Sub Form_Load()
Me.Show
Command1.Caption = "Print Form"
End Sub;
No Comments to show
Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.
Adding your comment. Please wait...
Thanks for adding your comment!. After further review it will be added.
There was a problem adding your comment. Please try again.
Please complete all the fields in the form before sending.