[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~
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
1 Attachment(s)
Re: Print all controls in a PictureBox (not image)
Thanks for the information.
However that is not i wanted. My form is with vertical and horizontal scroll bar, which the contents inside the form is much bigger than my screen resolution. (Kindly refer to my attachment.) I need to print ALL contents inside the form, is it possible?
I have researched from many websites, they only capable to print the viewable contents from my screen, but not all the contents with scroll bars. Any idea? :confused:
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.
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/