|
-
Sep 14th, 2010, 02:36 AM
#1
Thread Starter
Junior Member
[Resolved] Print all controls in a PictureBox (not image)
Anyone knows how to print all the controls inside the PictureBox?
I have a PictureBox control with vertical and horizontal scroll bar. This scrollable PictureBox is much more bigger than my screen resolution. Inside this PictureBox it contains a lot of other controls, for example: line, TextBox, Label, Command etc.
The problem is am I able to print all the controls in this PictureBox without seeing the vertical and horizontal scrollbar?
I have tried so much as most of the examples are only capable to print the PictureBox which is within screen resolution, which more or less like print screen feature. Help~
Last edited by pu8y; Sep 15th, 2010 at 04:41 AM.
Reason: Problem solved.
-
Sep 14th, 2010, 04:25 AM
#2
Re: Print all controls in a PictureBox (not image)
there is a printscreen example from microsoft, which will print the entire picturebox, with contents, you would have to set the scrollbars to not visible before capturing, if you did not want them to show, the printed output is scaled to printer page size
i have tested the code in the example and it works well, has more options than your requirement
http://support.microsoft.com/default...b;en-us;161299
alternatively you can loop through all controls and print each that has container of the picturebox, at the position they are located in the picturebox, and with any required properties (font, size etc), to match how they are displayed on screen
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 14th, 2010, 08:15 PM
#3
Thread Starter
Junior Member
-
Sep 14th, 2010, 10:01 PM
#4
Re: Print all controls in a PictureBox (not image)
Considering you have an scrollable PictureBox on top of the Form, the Form surface is not visible to the user, then the Form Hdc and Picture properties could be used to store the real content you need to Print (the complete PictureBox with all the controls it has inside), then this should work:
Code:
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
Private Const PRF_OWNED = &H20& ' Draw all owned windows
Private Sub Command1_Click()
Dim rv As Long
Me.AutoRedraw = True
rv = SendMessage(Picture1.hwnd, WM_PAINT, Me.hDC, 0) 'Paint the PicBox background
rv = SendMessage(Picture1.hwnd, WM_PRINT, Me.hDC, _
PRF_CHILDREN + PRF_CLIENT + PRF_OWNED) 'Paint the PicBox Controls
Set Me.Picture = Me.Image 'Persist the Image in the Form into Picture
Me.AutoRedraw = False
' Print:
Printer.PaintPicture Me.Picture, 0, 0
Printer.EndDoc
' Clear Form:
Me.Cls
Set Me.Picture = Nothing
End Sub
I trigger the event with a CommandButton but you can use anything else if you want to.
Last edited by jcis; Sep 14th, 2010 at 10:07 PM.
-
Sep 15th, 2010, 01:23 AM
#5
Thread Starter
Junior Member
Re: Print all controls in a PictureBox (not image)
Thanks Jcis, it works!
For more details can refer to http://support.microsoft.com/kb/230502/EN-US/
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
|