代码:
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 LongPrivate Sub Command1_Click()
Dim rv As Long
rv = SendMessage(Frame1.hwnd, WM_PAINT, Picture1.hdc, 0)
rv = SendMessage(Frame1.hwnd, WM_PRINT, Picture1.hdc, PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
Printer.Print " "
Printer.PaintPicture Picture2.Image, 100, -50
Printer.EndDoc
End Sub

解决方案 »

  1.   

    为啥不用setparent?
      

  2.   

    看不懂
    但是把第二句改成这个就没有边框
    rv = SendMessage(Frame1.hwnd, WM_PRINT, Picture1.hdc, PRF_CHILDREN + PRF_NONCLIENT + PRF_OWNED)
      

  3.   

    不行啊,第二句改成
    rv = SendMessage(Frame1.hwnd, WM_PRINT, Picture1.hdc, PRF_CHILDREN + PRF_NONCLIENT + PRF_OWNED)
    是没有边框,但是frame中的text、frame控件全部都没有加载到picture1容器中,只加载label控件。等同于我把第二句注释掉
      

  4.   

    setparent是可以加载到picture1容器中,但是似乎是直接拷贝到picture1中,用Printer.PaintPicture Picture2.Image, 100, -50
    打印是空白
      

  5.   

    在frame里面再放一个 picture控件,把所有控件都放picture上
      

  6.   

    事先就用两个 PictureBox,其中一种作窗体控件的容器,另一个作打印媒介(空)。注意:两个不要互相嵌套,将第二个隐藏的第一个后面。SendMessage 发送的是 PictureBox1。下面是有两个 Label 的窗体打印的例子。
    Private Const twipFactor = 1440
    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 windows.
    Private Const PRF_OWNED = &H20&    ' Draw all owned windows.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 LongPrivate Sub Form_Load()
       Dim sWide As Single, sTall As Single
       Dim rv As Long   Me.ScaleMode = vbTwips   ' default
       sWide = 8.5
       stall = 11   ' or 14, etc.
       Me.Width = twipFactor * sWide
       Me.Height = twipFactor * stall
       With Picture1
          .Top = 0
          .Left = 0
          .Width = twipFactor * sWide
          .Height = twipFactor * stall
       End With
       With Picture2
          .Top = 0
          .Left = 0
          .Width = twipFactor * sWide
          .Height = twipFactor * stall
       End With
       With Label1
          .Caption = "Top"
          .Left = Me.Width / 2
          .Top = 0
       End With
       With Label2
          .Caption = "Bottom"
          .Top = (twipFactor * stall) - .Height * 2
          .Left = Me.Width / 2
       End With
       Me.Visible = True
       DoEvents   Picture1.SetFocus
       Picture2.AutoRedraw = True
       rv = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hDC, 0)
       rv = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hDC, _
       PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
       Picture2.Picture = Picture2.Image
       Picture2.AutoRedraw = False   Printer.Print ""
       Printer.PaintPicture Picture2.Picture, 0, 0
       Printer.EndDoc
    End Sub