I've used a picturebox to create a directed graph. The nodes on the graph
are controls. How do I print the model?
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)
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
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....
MS Dev MVP
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
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.