我找到一个打印当前窗体的函数,用起来很不错的,感觉也很好。
但是由于窗体打印只可以打印可见窗体,所以我通过循环多页的
方式打印全部数据,但是这个函数一进行第二次调用循环就报错,
说我当前的打印机不支持位图打印,但是在第一次调用的时候就
没问题,我把调用函数和打印函数都贴出来,大家看看。Sub PrintMe()
            '取消背景图片
            Me.Picture = LoadPicture("")
            '设置纸型
            Call SelectForm("syt", Me.hwnd)  'syt是自定义纸张
            '打印
            Me.PrintForm
            '卸载窗体
            If  printnumber>1  Then
                printnumber=printnumber-1
                PrintMe
            Else
                Unload Me
            End If
End SubPublic Function SelectForm(FormName As String, ByVal MyhWnd As Long) As Integer
    Dim nSize As Long           ' Size of DEVMODE
    Dim pDevMode As DEVMODE
    Dim PrinterHandle As Long   ' Handle to printer
    Dim hPrtDC As Long          ' Handle to Printer DC
    Dim PrinterName As String
    Dim aDevMode() As Byte      ' Working DEVMODE
    Dim FormSize As SIZEL
    
    PrinterName = Printer.DeviceName  ' Current printer
    hPrtDC = Printer.hdc              ' hDC for current Printer
    SelectForm = FORM_NOT_SELECTED    ' Set for failure unless reset in code.
    
    ' Get a handle to the printer.
    If OpenPrinter(PrinterName, PrinterHandle, 0&) Then
        ' Retrieve the size of the DEVMODE.
        nSize = DocumentProperties(MyhWnd, PrinterHandle, PrinterName, 0&, 0&, 0&)
        ' Reserve memory for the actual size of the DEVMODE.
        ReDim aDevMode(1 To nSize)
    
        ' Fill the DEVMODE from the printer.
        nSize = DocumentProperties(MyhWnd, PrinterHandle, PrinterName, _
                aDevMode(1), 0&, DM_OUT_BUFFER)
        ' Copy the private (predefined) portion of the DEVMODE.
        Call CopyMemory(pDevMode, aDevMode(1), Len(pDevMode))
        
        ' Change the appropriate member in the DevMode.
        ' In this case, you want to change the form name.
        pDevMode.dmFormName = FormName & Chr(0)  ' Must be NULL terminated!
        ' Set the dmFields bit flag to indicate what you are changing.
        pDevMode.dmFields = DM_FORMNAME
    
        ' Copy your changes back, then update DEVMODE.
        Call CopyMemory(aDevMode(1), pDevMode, Len(pDevMode))
        nSize = DocumentProperties(MyhWnd, PrinterHandle, PrinterName, _
                aDevMode(1), aDevMode(1), DM_IN_BUFFER Or DM_OUT_BUFFER)
    
        nSize = ResetDC(hPrtDC, aDevMode(1))   ' Reset the DEVMODE for the DC.
    
        ' Close the handle when you are finished with it.
        ClosePrinter (PrinterHandle)
        ' Selection Succeeded! But was Form Added?
        If SelectForm <> FORM_ADDED Then SelectForm = FORM_SELECTED
    Else
        SelectForm = FORM_NOT_SELECTED   ' Selection Failed!
    End If
End Function