|
-
Sep 6th, 2004, 11:23 PM
#1
Printing a Picture Box (non standard questions) [surely RESOLVED]
I want to print a picture box using PainPicture but I have a few questions I could not find answered on the forum.
1. What if the Picture Box is larger than the form it is on (a part of it is cut off)? Will it still print the whole picture?
2. If I have labes with text (captions) embeded in the picture box along with the picture, will they be printed too? If not, how can that be achieved?
Last edited by baja_yu; Sep 7th, 2004 at 12:55 AM.
-
Sep 6th, 2004, 11:29 PM
#2
1. If AutoRedraw property of PictureBox is true then it will print whole picture.
2. Use Form1.PrintForm method
-
Sep 6th, 2004, 11:35 PM
#3
Originally posted by Deepak Sakpal
1. If AutoRedraw property of PictureBox is true then it will print whole picture.
2. Use Form1.PrintForm method
Just to say that I dont have a printer here so I cant test myself to find out the answers.
Regarding the answer to number 2: But I only want to print the contents of the Picture box, not the entire form. And wont PrintForm cut of the image if the picturebox can't fit the form?
-
Sep 6th, 2004, 11:48 PM
#4
i suggested the simplest method
anyways here you go
VB Code:
Option Explicit
Private Declare Function SendMessage Lib "user32.dll" 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
Private Const PRF_OWNED = &H20& ' Draw all owned windows
'Note - Box could also be a Form, if desired.
Public Sub PrintPictureBox(Box As PictureBox, _
Optional X As Single = 0, _
Optional Y As Single = 0)
Dim rv As Long
Dim ar As Boolean
On Error GoTo Exit_Sub
With Box
'Save ReDraw value
ar = .AutoRedraw
'Set persistance
.AutoRedraw = True
'Wake up printer
Picture2.Print
'Draw controls to picture box
rv = SendMessage(.hwnd, WM_PAINT, .hDC, 0)
rv = SendMessage(.hwnd, WM_PRINT, .hDC, _
PRF_CHILDREN Or PRF_CLIENT Or PRF_OWNED)
'Refresh image to picture property
.Picture = .Image
'Copy picture to Printer
Picture2.PaintPicture .Picture, X, Y
'Restore backcolor (Re-load picture if picture was used)
Box.Line (0, 0)-(.ScaleWidth, .ScaleHeight), .BackColor, BF
'Restore ReDraw
.AutoRedraw = ar
End With
Exit_Sub:
If Err.Number Then MsgBox Err.Description, vbOKOnly, "Printer Error!"
End Sub
'USAGE - Add two picture boxes(Picture1,Picture2) and a command button (Command1) to a new form.
' Add various controls to the picture box.
' Run this code, and press the button to print.
Private Sub Command1_Click()
PrintPictureBox Picture1, 1000, 1000
End Sub
-
Sep 6th, 2004, 11:59 PM
#5
Thanks, I will try it out tomorrow when I get to a printer.
-
Sep 7th, 2004, 12:01 AM
#6
no need of printer
start a new project, paste this code & boom.
-
Sep 7th, 2004, 12:43 AM
#7
Oh.... guess I didnt read the code right away.... so this does not send to the printer, just adds all the stuff to the Picture2 picture box.
So I need to add the Printing part... no problem... That I know how...
-
Sep 7th, 2004, 12:46 AM
#8
u can just replace Picture2 with Printer.
-
Sep 7th, 2004, 12:48 AM
#9
Ok.. one more:
PrintPictureBox Picture1, 1000, 1000
This adds an offset to the image. I guess you added this for the margin so the image does not get cut on the printer (as the printer cant print all the way to the edges of the paper).
If that is the case I will sett this to zero as I have compensated for that already in the picture itself.
-
Sep 7th, 2004, 12:50 AM
#10
Originally posted by baja_yu
PrintPictureBox Picture1, 1000, 1000
This adds an offset to the image. I guess you added this for the margin so the image does not get cut on the printer (as the printer cant print all the way to the edges of the paper).
If that is the case I will sett this to zero as I have compensated for that already in the picture itself.
Ur guess is absolutely correct.
-
Sep 7th, 2004, 12:55 AM
#11
Ok. Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|