Sergio Luiz
Member
I have a routine that I have inside a DataGridView, I want each row of the DataGridView to be printed on a page.
but I'm not getting you to change the page in the printdocument, see the routine
my code :
but I'm not getting you to change the page in the printdocument, see the routine
my code :
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
Last edited: