I would like help on a report I'm creating via code ...
Next in the data insertion part of a datagridview
I am having problems, when I use the command While
on page printPreview
the searched data appears, but when I launch the command to print it no data is printed , header and footer only.
But when I use the command For
it works perfectly, but I can not add more than 1 page because of For
.
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pdoc.PrintPage
'Margens
Dim margemEsq As Single = e.MarginBounds.Left
Dim margemSup As Single = e.MarginBounds.Top
Dim margemDir As Single = e.MarginBounds.Right
Dim margemInf As Single = e.MarginBounds.Bottom
'Fontes
Dim fonteTitulo As Font
Dim fonteRodape As Font
Dim fonteNormal As Font
fonteTitulo = New Font("Verdana", 15, FontStyle.Bold)
fonteRodape = New Font("Verdana", 8)
fonteNormal = New Font("Verdana", 10)
'Linhas
Dim caneta As New Pen(Color.Black, 1)
'e.Graphics.DrawLine(caneta, margemEsq, 60, margemDir, 60)
e.Graphics.DrawImage(Image.FromFile("C:\" & "vb.gif"), 100, 68)
'e.Graphics.DrawLine(caneta, margemEsq, 160, margemDir, 160)
'e.Graphics.DrawString("Catálogo de Produtos", fonteTitulo, Brushes.Blue, margemEsq + 275, 80, New StringFormat())
'impressão do titulo das colunas
Dim fonteColuna As New Font("Arial", 16)
e.Graphics.DrawString("Código", fonteColuna, Brushes.Red, margemEsq, 140, New StringFormat())
e.Graphics.DrawString("Produto", fonteColuna, Brushes.Red, margemEsq + 100, 140, New StringFormat())
e.Graphics.DrawString("Preço", fonteColuna, Brushes.Red, margemEsq + 500, 140, New StringFormat())
e.Graphics.DrawLine(caneta, margemEsq, 170, margemDir, 170)
Dim linhasPorPagina = e.MarginBounds.Height / fonteNormal.GetHeight(e.Graphics) - 6
Dim linhaAtual = 1
' While num < DataGridView1.RowCount - 1
' ou
'for num < DataGridView1.RowCount - 1
Dim posicaoDaLinha = margemSup + (linhaAtual * fonteNormal.GetHeight(e.Graphics) + 70)
Dim strings As String = DataGridView1.Rows(num).Cells(0).Value.ToString()
e.Graphics.DrawString(strings, fonteNormal, Brushes.Black, margemEsq, posicaoDaLinha, New StringFormat())
linhaAtual += 1
'----------------------------
e.Graphics.DrawLine(caneta, margemEsq, margemInf, margemDir, margemInf)
e.Graphics.DrawString(System.DateTime.Now, fonteRodape, Brushes.Black, margemEsq, margemInf, New StringFormat())
e.Graphics.DrawString("Pag. " & paginaAtual.ToString, fonteRodape, Brushes.Black, margemDir - 50, margemInf, New StringFormat())
paginaAtual += 1
End Sub