Printing a picturebox when it contains controls.

Printing a picturebox when it contains controls.

Post by Jurrinus ten Brink » Sun, 14 Nov 1999 04:00:00

I've used a picturebox to create a directed graph. The nodes on the graph
are controls. How do I print the model?



Printing a picturebox when it contains controls.

Post by Jim Deutc » Tue, 16 Nov 1999 04:00:00

You can print a screen capture, but the resolution is poor.  Here's some

If your canvas is the printer object, add an enddoc and it
will print.  To put it on the clipboard, use a picturebox as your canvas
then use Clipboard.SetData to paste.

For alt-PrintScrn, change the StretchBlt() parameters to capture only the
portion of the screen occupied by the active window.

Private Declare Function CreateDC& Lib "gdi32" Alias "CreateDCA" (ByVal
lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As
String, lpInitData As Any)
Private Declare Function DeleteDC& Lib "gdi32" (ByVal hdc As Long)
Private Declare Function StretchBlt& Lib "gdi32" (ByVal hdc As Long, ByVal x
As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal
hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As
Long, ByVal nSrcHeight As Long, ByVal dwRop As Long)
Private Const SRCCOPY& = &HCC0020

Sub CopyScreen(canvas As Object)
Dim screendc&
    canvas.AutoRedraw = True
    screendc = CreateDC("DISPLAY", "", "", 0&)
    tempLong = StretchBlt(canvas.hDC, 0, 0, canvas.Width, canvas.Height,
screendc, 0, 0, Screen.Width, Screen.Height, SRCCOPY)
    tempLong = DeleteDC(screendc)
    canvas.AutoRedraw = False

End Sub

A much better way is to redraw the entire graph to the Printer object.
You'll have to write a subroutine to draw lines that reproduce the
appearance of your nodes....

Jim Deutch

>I've used a picturebox to create a directed graph. The nodes on the graph
>are controls. How do I print the model?



1. Print/save entire PictureBox w/ child controls


Though I've asked this question before, I have some new
twists on this problem.

My project (which is similar to MS Paint, but with VB
controls on the drawing that can be manipulated) needs to
be able to print out the entire contents of a picturebox,
part of which may not be visible on-screen, as well as
save it as a bitmap.

Up until now, using WM_PAINT and WM_PRINT messages with
appropriate flags (ie. PRF_CHILDREN, etc.) has worked
fine.  But since then, I've added UserControls that appear
on the drawing surface that contain lightweight controls;
when using this method, the control is not painted and is
completely transparent.  Likewise, UserControls that use
picture boxes won't paint the bitmap assigned to it,
showing only the border of the picture box with the
interior transparent.

I've tried manually adding shapes and images to produce
the final image, but that won't take the Z-order into

If you have any idea how to go about solving this issue, I
would greatly appreciate it.


2. about the algorithm for finding iso-contour in 2D image.

3. Printing Image of all controls in picture box to 2nd picturebox

4. Cinema 4d / Zeit stauchen und dehnen / de

5. How to print graphics in picturebox control

6. EG ViSC'98 Call for Paper (2nd try)

7. Ensuring an edit control contains numbers only

8. 3D or shadow text?

9. Transparent PictureBox control

10. How to save WMF to BMP without PictureBox Control

11. vb6 Picturebox used in activex-control with access report

12. PictureBox Control and small icon

13. create file from picturebox control