Results 1 to 3 of 3

Thread: Print Preview

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2011
    Posts
    132

    Print Preview

    Ok I generate a print preview, the only thing is, if there is enough data to fill like 2-3 pages I don't know how to generate a new page. It only fills the first page and that's it....

    Code:
    Private Doc As New PrintDocument()
    
    Private Sub btnPrint_Click(sender As System.Object, e As System.EventArgs) Handles btnPrint.Click
            Dim ppDlg As New PrintPreviewDialog()
            ppDlg.ShowIcon = False
            ppDlg.Document = Doc
            ppDlg.Show()
            AddHandler Doc.PrintPage, AddressOf Print_PrintPage
        End Sub
    
    Dim g As Graphics = e.Graphics
            g.DrawImage(Roll_Off_Manager.My.Resources.Elk, 0, 10)
            g.DrawString("City of Elk City Roll-Off Account", New Font("arial", 18, FontStyle.Bold), Brushes.Black, 230, 110)
            Dim name As String = cboFinalAccounts.Text
            Dim stopName As Integer
            Dim startNumber, stopNumber As Integer
            For i As Integer = 0 To name.Length - 1
                If name.Substring(i, 1) = "(" Then
                    stopName = i
                    startNumber = i + 1
                ElseIf name.Substring(i, 1) = ")" Then
                    stopNumber = i - 1
                End If
            Next
            g.DrawString(name.Substring(0, stopName - 1), New Font("arial", 14, FontStyle.Italic), Brushes.Black, 230, 150)
            g.DrawString("Account #: ", New Font("arial", 10, FontStyle.Bold), Brushes.Black, 550, 170)
            g.DrawString(name.Substring(startNumber, stopNumber - stopName), New Font("arial", 10, FontStyle.Bold), Brushes.Black, 625, 170)
            g.DrawString(txtPhone.Text, New Font("arial", 11), Brushes.Black, 230, 175)
            g.DrawString(txtAddress.Text, New Font("arial", 10), Brushes.Black, 100, 235)
            Try
                con.ConnectionString = dbProvider & dbSource
                con.Open()
                sql = "SELECT * FROM FinaledAccounts WHERE CustomerID = " & CInt(tsslCustomer.Text)
                da = New OleDb.OleDbDataAdapter(sql, con)
                ds.Clear()
                da.Fill(ds, "FinaledAccounts")
                con.Close()
                Dim setup, final As Date
                If ds.Tables("FinaledAccounts").Rows.Count > 0 Then
                    setup = ds.Tables("FinaledAccounts").Rows(0).Item(9)
                    final = ds.Tables("FinaledAccounts").Rows(0).Item(14)
                End If
                g.DrawString("__________________________________________________________________________________", New Font("arial", 10), Brushes.Black, 100, 190)
                g.DrawString(setup.ToString("MM/dd/yyyy") & " - " & final.ToString("MM/dd/yyyy"), New Font("arial", 10, FontStyle.Bold), Brushes.Black, 340, 210)
                g.DrawString("__________________________________________________________________________________", New Font("arial", 10), Brushes.Black, 100, 215)
                g.DrawString("Invoice #", New Font("arial", 8), Brushes.Black, 60, 270)
                g.DrawString("Ticket #", New Font("arial", 8), Brushes.Black, 120, 270)
                g.DrawString("Date", New Font("arial", 8), Brushes.Black, 180, 270)
                g.DrawString("Unit", New Font("arial", 8), Brushes.Black, 240, 270)
                g.DrawString("Weight", New Font("arial", 8), Brushes.Black, 280, 270)
                g.DrawString("Overweight", New Font("arial", 8), Brushes.Black, 330, 270)
                g.DrawString("Mileage", New Font("arial", 8), Brushes.Black, 400, 270)
                g.DrawString("Service", New Font("arial", 8), Brushes.Black, 460, 270)
                g.DrawString("Delivery", New Font("arial", 8), Brushes.Black, 520, 270)
                g.DrawString("Rental", New Font("arial", 8), Brushes.Black, 580, 270)
                g.DrawString("Extra", New Font("arial", 8), Brushes.Black, 640, 270)
                g.DrawString("Driver", New Font("arial", 8), Brushes.Black, 690, 270)
                g.DrawString("Subtotal", New Font("arial", 8), Brushes.Black, 730, 270)
                g.DrawString("______________________________________________________________", New Font("arial", 8), Brushes.Black, 280, 255)
                g.DrawString("Costs and Fees", New Font("arial", 8, FontStyle.Bold), Brushes.Black, 430, 250)
                g.DrawString("_________________________________________________________________________________________________________________", New Font("arial", 8), Brushes.Black, 60, 275)
                Dim down As Integer = 290
                Dim ticket, driver As String
                For i As Integer = 0 To dgvFinaledCharges.Rows.Count - 1
                    g.DrawString(dgvFinaledCharges.Rows(i).Cells(0).Value, New Font("arial", 8), Brushes.Black, 60, down)
                    ticket = IIf(IsDBNull(dgvFinaledCharges.Rows(i).Cells(1).Value), String.Empty, dgvFinaledCharges.Rows(i).Cells(1).Value)
                    g.DrawString(ticket, New Font("arial", 8), Brushes.Black, 120, down)
                    g.DrawString(dgvFinaledCharges.Rows(i).Cells(2).Value, New Font("arial", 8), Brushes.Black, 180, down)
                    g.DrawString(dgvFinaledCharges.Rows(i).Cells(3).Value, New Font("arial", 8), Brushes.Black, 240, down)
                    g.DrawString(dgvFinaledCharges.Rows(i).Cells(9).Value, New Font("arial", 8), Brushes.Black, 280, down)
                    g.DrawString(dgvFinaledCharges.Rows(i).Cells(14).Value, New Font("arial", 8), Brushes.Black, 330, down)
                    g.DrawString(dgvFinaledCharges.Rows(i).Cells(10).Value, New Font("arial", 8), Brushes.Black, 400, down)
                    g.DrawString(dgvFinaledCharges.Rows(i).Cells(11).Value, New Font("arial", 8), Brushes.Black, 460, down)
                    g.DrawString(dgvFinaledCharges.Rows(i).Cells(12).Value, New Font("arial", 8), Brushes.Black, 520, down)
                    g.DrawString(dgvFinaledCharges.Rows(i).Cells(13).Value, New Font("arial", 8), Brushes.Black, 580, down)
                    g.DrawString(dgvFinaledCharges.Rows(i).Cells(15).Value, New Font("arial", 8), Brushes.Black, 640, down)
                    driver = IIf(IsDBNull(dgvFinaledCharges.Rows(i).Cells(17).Value), String.Empty, dgvFinaledCharges.Rows(i).Cells(17).Value)
                    g.DrawString(driver, New Font("arial", 8), Brushes.Black, 690, down)
                    g.DrawString(dgvFinaledCharges.Rows(i).Cells(19).Value, New Font("arial", 8), Brushes.Black, 730, down)
                    down += 20
                Next
                g.DrawString("_________________________________________________________________________________________________________________", New Font("arial", 8), Brushes.Black, 60, down - 10)
                g.DrawString("Total Tons Emptied: ", New Font("arial", 11, FontStyle.Bold), Brushes.Black, 501, down + 20)
                g.DrawString("Total:", New Font("arial", 11, FontStyle.Bold), Brushes.Black, 610, down + 50)
                g.DrawString(tsslTotalTons.Text.Substring(0, (tsslTotalTons.Text.Length - 19)), New Font("arial", 11, FontStyle.Bold), Brushes.Black, 670, down + 20)
                g.DrawString(tsslTotalRevenue.Text, New Font("arial", 11, FontStyle.Bold), Brushes.Black, 670, down + 50)
    don't worry about most of the code it's just pulling data from database and printing necessary charges to the invoice, but if the invoice is more than 1 page then I don't know what to do because it only generates 1 page.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Print Preview

    When you read the documentation for the PrintPage event, did you miss this part?
    In addition to specifying the output, you can indicate if there are additional pages to print by setting the PrintPageEventArgs.HasMorePages property to true. The default is false, which indicates that there are no more pages to print.
    The PrintPage event will, as the name suggests, print a page. If you have multiple pages to print then you need to raise the PrintPage event multiple times. The PrintPage event will be raised again if and only if HasMorePages is True. It's up to you to keep track of what page you're currently printing and what data goes on that page.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2011
    Posts
    132

    Re: Print Preview

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width