none
Printdocument fazer mudanças de pagina documento RRS feed

  • Pergunta

  • Estou com uma rotina que tenho dentro de um DataGridView , quero que cada linha do DataGridView seja impresso em uma pagina.

    mas não estou conseguindo que mude de pagina no printdocument , veja a rotina

    meu código

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim margins As Margins = New Margins(Convert.ToInt16("5"), Convert.ToInt16("5"), Convert.ToInt16("5"), Convert.ToInt16("5"))
            Dim LarguraEtiqueta As Single = Convert.ToSingle("100")
            Dim AlturaEtiqueta As Single = Convert.ToSingle("50")
            Dim Tamanhopag = New PaperSize("First custom size", 100, 50)
            PrintDocument1.DefaultPageSettings.PaperSize = Tamanhopag
            PrintDocument1.DefaultPageSettings.PaperSize.Height = AlturaEtiqueta
            PrintDocument1.DefaultPageSettings.PaperSize.Width = LarguraEtiqueta
            PrintDocument1.PrinterSettings.PrinterName = Trim(GPrintName)
            PrintDocument1.DefaultPageSettings.Margins = margins

            PrintPreviewDialog1.Document = PrintDocument1

            PrintPreviewDialog1.ShowDialog()
        End Sub

    Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
            Dim LarguraEtiqueta As Single = Convert.ToSingle("100")
            Dim AlturaEtiqueta As Single = Convert.ToSingle("50")
            Dim Tamanhopag = New PaperSize("First custom size", 100, 50)
            e.PageSettings.PaperSize = Tamanhopag
            e.PageSettings.PaperSize.Height = AlturaEtiqueta
            e.PageSettings.PaperSize.Width = LarguraEtiqueta

            Dim TTLrows As Int64 = (Me.DataGridView1.RowCount - 1)
            Dim FNormal = New Font("Verdana", 10)
            With Me.DataGridView1
                For Xx = 0 To TTLrows
                    CheckVal = .Rows(Xx).Cells(10).Value
                    If CheckVal = "True" Then
                        'imprime dados
                        cLinha1 = "No.N.F : " & Trim(.Rows(Xx).Cells(0).Value)
                        e.Graphics.DrawString(cLinha1, FNormal, Brushes.Black, 0, 0 + 2, New StringFormat())
                    End If
                Next
            End With
        End Sub

     
    quarta-feira, 19 de fevereiro de 2020 20:05