我原来用FORMPRINT方法打印窗体上显示的数据
现在客户需要将打印出来的资料在打印的时候也产生一个和打印出来一样的文件
方便邮件附件传送。
我该怎么把窗体的内容导到文件那?
还有就是显示的数据位置和原来的一样怎么实现阿?

解决方案 »

  1.   

    Option ExplicitPrivate Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As LongPrivate Sub Command1_Click()
        '从屏幕上截图
        picCopy.Width = Width
        picCopy.Height = Height - 300    BitBlt picCopy.hDC, 0, 0, Width - 1, Height - 300, Me.hDC, 0, 0, &HCC0020
        SavePicture picCopy.Image, "c:\aa.bmp"
    End SubPrivate Sub Form_Load()
        '在窗口中加一个PICTUREBOX控件,改名为picCopy
        picCopy.Visible = False
        picCopy.AutoRedraw = True
    End Sub
      

  2.   


    Private Function CaptureWindow(ByVal hWndSrc As Long, _
        ByVal bClient As Boolean, ByVal LeftSrc As Long, _
        ByVal TopSrc As Long, ByVal WidthSrc As Long, _
        ByVal HeightSrc As Long) As PicturePrivate Sub command1_Click()
    Set Picture1.Picture = CaptureForm(Me)
    End SubPrivate Function CaptureForm(frm As Form) As PictureWith frm
        Set CaptureForm = CaptureWindow(.hWnd, False, 0, 0, _
                .ScaleX(.Width, vbTwips, vbPixels), _
                .ScaleY(.Height, vbTwips, vbPixels))
    End With
    End Function
      

  3.   

    截图不一定能把FORM全截取下来
    那怎么办?
      

  4.   

    Private Function CaptureWindow(ByVal hWndSrc As Long, _
        ByVal bClient As Boolean, ByVal LeftSrc As Long, _
        ByVal TopSrc As Long, ByVal WidthSrc As Long, _
        ByVal HeightSrc As Long) As PicturePrivate Sub command1_Click()
    Set Picture1.Picture = CaptureForm(Me)
    End SubPrivate Function CaptureForm(frm As Form) As Picture
    With frm
        Set CaptureForm = CaptureWindow(.hWnd, False, 0, 0, _
                .ScaleX(.Width, vbTwips, vbPixels), _
                .ScaleY(.Height, vbTwips, vbPixels))
    End With
    End Function
      

  5.   

    楼上的,我怎么存到硬盘?
    还有你的这个截取的是ACTIVE窗体么?
      

  6.   

    应该是可以的,既然PrintForm可以打印出来的话,你可以在输出前调整一下窗体的位置。
      

  7.   

    楼上的,我怎么存到硬盘?savepicture Picture1.Picture,"c:\123.bmp"
      

  8.   

    楼主,请说清楚点啊!我觉得cuizm(射天狼)写的原代码很清楚的啊!