想要打印报告,能够打印单页,即最多45行,其余行不打印,无法再创建新页面。 [英] Wanted to print a report, able to print a single page i.e upto 45 lines and the remaining lines are not printing, unable to create further new pages.

查看:47
本文介绍了想要打印报告,能够打印单页,即最多45行,其余行不打印,无法再创建新页面。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am using VB.net 2010 and MS Access and I need to print a report, I am able to print a single page i.e upto 45 lines and the remaining lines are not printing, unable to create further new pages. Please help, thanks in advance

This is my code:

Public Class frmReport
    Dim conn As New OleDb.OleDbConnection
    Dim strMonthNo As String
    Dim y As Integer
    
    
    Private Sub LoadStocksOutReport()
        Dim totTransactions As Integer
        Dim totSales As Double
        Dim totCreditSales As Double
        Dim totPayments As Double
        Dim sqL As String
        Dim GridRow As DataGridViewRow

        
        Try
            If Not conn.State = ConnectionState.Open Then
                'open connection
                conn.Open()
            End If


            If frmFilterMonthlyReport.chkMonthly.Checked = True Then

                sqL = "SELECT [invoiceNo], [tDate], [customer_Name], [job], [cashOrCredit], [totalAmount] FROM transactions WHERE  tDate LIKE '" & strMonthNo & "%' AND tDate LIKE '%" "' ORDER BY invoiceNo"
            Else
                sqL = "SELECT [invoiceNo], [tDate], [customer_Name], [job], [cashOrCredit], [totalAmount] FROM transactions WHERE  tDate LIKE '%" "' ORDER BY invoiceNo"
            End If

            Dim cmd = New OleDb.OleDbCommand(sqL, conn)
            Dim dr As OleDb.OleDbDataReader
            dr = cmd.ExecuteReader()

            
            dgw.Rows.Clear()
            totTransactions = 0
            totSales = 0.0
            totCreditSales = 0.0
            totPayments = 0.0
            y = 0
            Do While dr.Read = True
                dgw.Rows.Add(dr("invoiceNo"), Format(dr("tDate"), "dd/MM/yyyy"), dr("customer_Name"), dr("job"), dr("cashOrCredit"), Format(dr("totalAmount"), "#,##0.00"))

                y += 19
                totTransactions += 1
                totSales += dr("totalAmount")
                If dr("cashOrCredit").ToString = "Credit" Then
                    totCreditSales += dr("totalAmount")
                Else
                    totPayments += dr("totalAmount")
                End If
            Loop
            dgw.Height += y
            lblTotalStocksIn.Text = totTransactions
            lblTotalSales.Text = Format(totSales, "#,##0.00")
            lblTotalCredits.Text = Format(totCreditSales, "#,##0.00")
            lblTotalCashPayments.Text = Format(totPayments, "#,##0.00")

            Panel3.Location = New Point(Me.Panel3.Location.X, Me.Panel3.Location.Y + y)
        Catch ex As Exception
            MsgBox(ex.ToString)
        Finally
            conn.Close()
            conn.Dispose()
        End Try
    End Sub

    Private Sub frmMonthlyReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conn = New OleDb.OleDbConnection
        conn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.StartupPath & "\testDB.mdb"

        If frmFilterMonthlyReport.chkMonthly.Checked = True Then
            lblCollections.Text = "Sales for the Month of " & frmFilterMonthlyReport.cmbMonth.Text & " " & frmFilterMonthlyReport.cmbYear.Text
        Else
            frmFilterMonthlyReport.chkYearly.Checked = True
            lblTitle.Text = "Yearly Sales Report"
            lblCollections.Text = "Sales for the Year of " & frmFilterMonthlyReport.cmbYear.Text
        End If

        LoadStocksOutReport()
        lbldate.Text = Date.Now.ToString("dd-MM-yyyy")
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        
                Dim bm As New Bitmap(Me.Panel1.Width, Me.Panel1.Height)
                Panel1.DrawToBitmap(bm, New Rectangle(0, 0, Me.Panel1.Width, Me.Panel1.Height))
                e.Graphics.DrawImage(bm, 0, 40)
                Dim aPS As New PageSetupDialog
                aPS.Document = PrintDocument1
                
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PrintDialog1.Document = Me.PrintDocument1

        Dim ButtonPressed As DialogResult = PrintDialog1.ShowDialog()
        If (ButtonPressed = DialogResult.OK) Then
            Panel1.Height += y
            PrintDocument1.Print()
            Me.Close()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    
End Class





我尝试过:



上面的代码工作正常,打印单页,即最多45行,其他行无法打印,没有新页面打印剩余行。



What I have tried:

The above code is working fine to print a single page i.e upto 45 lines and further lines are unable to print and no new pages are being created to print the remaining lines.

推荐答案

设置 PrintPageEventArgs.HasMorePages属性(System.Dr) awing.Printing) [ ^ ]到 true 如果还有其他页面 - 默认为 false 表示没有更多页面。



然后,停止尝试将面板绘制为打印对象,并使用实际数据直接打印尝试采取位图。位图只能显示用户立即可见的部分,因此如果要打印多行,则只显示开始。通过PrintPageEventArgs.Graphics正确地完成工作并调用DrawString,如MSDN上的Printpage调用示例所示,这是唯一的方法!
Set the PrintPageEventArgs.HasMorePages Property (System.Drawing.Printing)[^] to true if you have further pages - it defaults to false indicating there are no more pages.

Then, stop trying to draw your panel as a print object, and use the actual data to print directly instead of trying to take a bitmap. The bitmap can only ever show the part that is immediately visible to the user, so if you have many lines to print then only the start is ever shown. Doing the job properly via the PrintPageEventArgs.Graphics and calling DrawString as shown in the Printpage call exampole on MSDN is the only way to do this!


这篇关于想要打印报告,能够打印单页,即最多45行,其余行不打印,无法再创建新页面。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆