PrintDocument and MorePages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nuwanhapugoda
    New Member
    • Mar 2016
    • 1

    PrintDocument and MorePages

    Please help me -- The first page of every page printed. The other pages are not printed anything. It's not a newly printed about 2000.

    Thanks You

    Nuwan Hapugoda
    nuwan@hapugoda. com
    sampath.hapugod [email protected]


    Im use Visual Studio 2010 -

    Code:
    Private Sub PrintInvoice()
            Dim pd As New PrintDocument
            AddHandler pd.PrintPage, AddressOf printpage
            PPD.Document = pd
            PPD.ShowDialog()
    
        End Sub
    
        Private Sub printpage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
    
    
            Dim dp As Single() = {20, 10, 20, 10}
    
            Dim frLarge As Font = New Font("Courier New", 15, FontStyle.Bold)
    
            Dim fr As Font = New Font("Courier New", 9, FontStyle.Regular)
            Dim frs As Font = New Font("Courier New", 8, FontStyle.Regular)
            Dim fb As Font = New Font("Courier New", 9, FontStyle.Bold)
    
            Dim drawp As Pen = New Pen(Brushes.Black, 1)
            Dim sformat As New StringFormat
            sformat.Alignment = StringAlignment.Center
    
    
            Dim yPos As Integer = 100
            Dim xPos As Integer = 100
            drawp.DashPattern = dp
    
            yPos = 90
            
    
            e.Graphics.DrawLine(drawp, xPos, yPos, 800, yPos)
          
    
            sformat.Alignment = StringAlignment.Near
            e.Graphics.DrawString("NIC ", fr, Brushes.Black, New Rectangle(xPos + 40, yPos, 100, fr.Height), sformat)
            e.Graphics.DrawString("Name with Initials ", fr, Brushes.Black, New Rectangle(xPos + 140, yPos, 150, fr.Height), sformat)
            e.Graphics.DrawString("Division ", fr, Brushes.Black, New Rectangle(xPos + 300, yPos, 100, fr.Height), sformat)
            e.Graphics.DrawString("Year ", fr, Brushes.Black, New Rectangle(xPos + 400, yPos, 100, fr.Height), sformat)
            e.Graphics.DrawString("Month ", fr, Brushes.Black, New Rectangle(xPos + 500, yPos, 100, fr.Height), sformat)
            e.Graphics.DrawString("RS ", fr, Brushes.Black, New Rectangle(xPos + 600, yPos, 100, fr.Height), sformat)
            e.Graphics.DrawString("Status ", fr, Brushes.Black, New Rectangle(xPos + 700, yPos, 100, fr.Height), sformat)
    
            yPos += fr.Height
            e.Graphics.DrawLine(drawp, xPos, yPos, 800, yPos)
            yPos += fr.Height
            Dim x As Single = 0
            For x = 0 To DataGridView1.RowCount - 1
                sformat.Alignment = StringAlignment.Near
                e.Graphics.DrawString(DataGridView1.Rows(x).Cells("***").Value, fr, Brushes.Black, New Rectangle(xPos + 5, yPos, 800, fr.Height), sformat)
                e.Graphics.DrawString(DataGridView1.Rows(x).Cells("NIC").Value, fr, Brushes.Black, New Rectangle(xPos + 40, yPos, 800, fr.Height), sformat)
                e.Graphics.DrawString(DataGridView1.Rows(x).Cells("Name with Initials").Value, fr, Brushes.Black, New Rectangle(xPos + 140, yPos, 150, fr.Height), sformat)
                e.Graphics.DrawString(DataGridView1.Rows(x).Cells("Division").Value, fr, Brushes.Black, New Rectangle(xPos + 300, yPos, 100, fr.Height), sformat)
                e.Graphics.DrawString(DataGridView1.Rows(x).Cells("Year").Value, fr, Brushes.Black, New Rectangle(xPos + 400, yPos, 100, fr.Height), sformat)
                e.Graphics.DrawString(DataGridView1.Rows(x).Cells("Month").Value, fr, Brushes.Black, New Rectangle(xPos + 500, yPos, 100, fr.Height), sformat)
                e.Graphics.DrawString(DataGridView1.Rows(x).Cells("RS").Value, fr, Brushes.Black, New Rectangle(xPos + 600, yPos, 100, fr.Height), sformat)
                e.Graphics.DrawString(DataGridView1.Rows(x).Cells("Status").Value, fr, Brushes.Black, New Rectangle(xPos + 700, yPos, 100, fr.Height), sformat)
                yPos += fr.Height + 12
            Next
    
    
            sformat.Alignment = StringAlignment.Near
            e.Graphics.DrawString("Total (Rs.) ", fb, Brushes.Black, New Rectangle(xPos + 5, yPos, 195, fr.Height), sformat)
            e.Graphics.DrawString(Format(Val(TxtTotal.Text), "#0.00"), fr, Brushes.Black, New Rectangle(xPos + 600, yPos, 100, fr.Height), sformat)
            yPos += fr.Height
            sformat.Alignment = StringAlignment.Near
            e.Graphics.DrawString("Row Count ", fb, Brushes.Black, New Rectangle(xPos + 5, yPos, 195, fr.Height), sformat)
            e.Graphics.DrawString(TextBox2.Text, fr, Brushes.Black, New Rectangle(xPos + 600, yPos, 100, fr.Height), sformat)
            yPos += fr.Height
    
            If (dp IsNot Nothing) Then
                e.HasMorePages = True
            Else
                e.HasMorePages = False
            End If
    
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            PrintInvoice()
        End Sub
    Last edited by nuwanhapugoda; Mar 22 '16, 11:21 AM.
Working...