我的程序中需要进行数据打印,数据显示在RichTextBox1中,我想程序在打印时,自动进行分页,并在每页下面中间显示“第X页共Y页”,请问如何实现?在线等,求高手帮忙,谢谢!

解决方案 »

  1.   

    你不是要自已编打印程序吧!否则用VB自带或CRYATAL REPORT 或ACTIVE REPORT或VSPRINT都很好分页;否则就头大ing.....
      

  2.   

    非常简单,我已经自行解决了。'打印--是否显示滚动条
    Public Declare Function GetScrollRange Lib "user32" (ByVal hwnd As Long, ByVal nBar As Long, lpMinPos As Long, lpMaxPos As Long) As Long
    Public Const SB_VERT = &H1
    Public Function ShowScroll(hwnd As Long) As Boolean '判断垂直滚动条的可见性
    Dim i As Long
    i = GetScrollRange(hwnd, SB_VERT, lpMinPos, lpMaxPos)
    ShowScroll = (lpMaxPos <> lpMinPos)
    End FunctionPrintDataForm窗体
    dyyl 这是richtextbox  控件Public Sub printdata(sj As String)
    Dim st As Long, cd As Long, l As Long, ym As Long
    On Error GoTo 89
    st = 1
    cd = 1
    ym = 1
    l = Len(sj)
    With PrintDataForm.dyyl
        Do
            If st + cd - 1 > l Then
                .Text = Mid$(sj, st, cd - 1)
                PrintDataForm.Label1.Caption = "第 " & ym & " 页"
                PrintDataForm.PrintForm
                Unload PrintDataForm
                GoTo 88
            Else
                .Text = Mid$(sj, st, cd)
                If ShowScroll(.hwnd) Then
                    cd = cd - 1
                    .Text = Mid$(sj, st, cd)
                    PrintDataForm.Label1.Caption = "第 " & ym & " 页"
                    PrintDataForm.Caption = ShowScroll(.hwnd)
                    PrintDataForm.PrintForm
                    Unload PrintDataForm
                    ym = ym + 1
                    st = cd + 1
                    cd = 1
                    If st > l Then GoTo 88
                Else
                    cd = cd + 1
                End If
            End If
        Loop
    End With
    88 Exit Sub
    89 MsgBox "对不起,可能您还没有安装打印机,或者打印机配置不正确,无法打印!"
      

  3.   

    我网站上有源码,你可以看看VB资料->查询“生产日报打印工具”═══════════════════
     免费的源码、工具网站,欢迎大家访问!
     http://www.j2soft.cn/
    ═══════════════════