while function using System.Drawing.Printing adds nothing?

Asked

Viewed 66 times

1

I would like help on a report I am creating via code...

Next in the data insertion part taking from a datagridview I’m in trouble, when I use the command While on the page printPreview appears the searched data, but when I launch the command to print it no data is printed, only header and footer. But when I use the command For it works perfectly, however I can not add more than 1 page because of the 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
  • 1

    Your question is unclear and, also, only these lines of code do not help the understanding. You don’t have to post the whole source, but it has to be something that you can understand what you’re doing.

  • I arranged the question please help me !!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.