如何打印PictureBox中的所有控件添加另外一个PictureBox,然后: Private Const WM_PAINT = &HF Private Const WM_PRINT = &H317 Private Const PRF_CLIENT = &H4& Private Const PRF_CHILDREN = &H10& Private Const PRF_OWNED = &H20& Private Const PHYSICALOFFSETX As Long = 112 Private Const PHYSICALOFFSETY As Long = 113 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 Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nindex _ As Long) As Long private Sub Form_Load() Picture1.AutoRedraw = True Picture2.AutoRedraw = True Picture2.BorderStyle = 0 Picture2.Visible = False End Sub Private Sub Command2_Click() Dim retval As Long, xmargin As Single, ymargin As Single Dim x As Single, y As Single x = 1: y = 1 With Printer .ScaleMode = vbInches xmargin = GetDeviceCaps(.hdc, PHYSICALOFFSETX) xmargin = (xmargin * .TwipsPerPixelX) / 1440 ymargin = GetDeviceCaps(.hdc, PHYSICALOFFSETY) ymargin = (ymargin * .TwipsPerPixelY) / 1440 Picture2.Width = Picture1.Width Picture2.Height = Picture1.Height DoEvents Picture1.SetFocus retval = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hdc, 0) retval = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hdc, _ PRF_CHILDREN + PRF_CLIENT + PRF_OWNED) DoEvents Printer.Print "" .PaintPicture Picture2.Image, x - xmargin, y - ymargin .EndDoc End With End Sub
Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4&
Private Const PRF_CHILDREN = &H10&
Private Const PRF_OWNED = &H20&
Private Const PHYSICALOFFSETX As Long = 112
Private Const PHYSICALOFFSETY As Long = 113
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 Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nindex _
As Long) As Long
private Sub Form_Load()
Picture1.AutoRedraw = True
Picture2.AutoRedraw = True
Picture2.BorderStyle = 0
Picture2.Visible = False
End Sub
Private Sub Command2_Click()
Dim retval As Long, xmargin As Single, ymargin As Single
Dim x As Single, y As Single
x = 1: y = 1
With Printer
.ScaleMode = vbInches
xmargin = GetDeviceCaps(.hdc, PHYSICALOFFSETX)
xmargin = (xmargin * .TwipsPerPixelX) / 1440
ymargin = GetDeviceCaps(.hdc, PHYSICALOFFSETY)
ymargin = (ymargin * .TwipsPerPixelY) / 1440
Picture2.Width = Picture1.Width
Picture2.Height = Picture1.Height
DoEvents
Picture1.SetFocus
retval = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hdc, 0)
retval = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hdc, _
PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
DoEvents
Printer.Print ""
.PaintPicture Picture2.Image, x - xmargin, y - ymargin
.EndDoc
End With
End Sub