PDA

View Full Version : [VB.NET] Problemi di stampa


daxdaxdax
10-08-2010, 16:03
Ciao a tutti!
In un mio progettino in vb.net, ci sono delle row di un datagridviewer da stampare:
Tutto funzionava regorarmente, quando ieri ho fatto una stampa di prova ed è comparsa sul foglio solo l'intestazione, non riportandomi le row.
La cosa strana è che sull'anteprima di stampa si vede tutto perfettamente.
Posto un po di codice, sperando di non aver scritto fesserie :D

Public Nitems As Integer

Private Sub BtnStampa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNstampa.Click
NrigaInLettura = 0
NrigheSuFoglio = 0
NpagineStampate = 0

Nitems = FRMvisualizzaOre.DGW.Rows.Count
If Nitems = 1 Then
MessageBox.Show("Nulla da stampare...", "Stampa", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Dim Anteprima As New PrintPreviewDialog
Anteprima.Document = PrintDocument1
Anteprima.MdiParent = FRMpadre
Anteprima.ShowIcon = False
Try
Anteprima.Show()
Catch ex As Printing.InvalidPrinterException
MessageBox.Show("Nessuna stampante installata nel computer.", "Stampa", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try

End Sub

Public Const nMaxRighePerPagina As Integer = 45 ' LIMITE DI RIGHE PER PAGINA

Public NrigaInLettura As Integer = 0
Public NrigheSuFoglio As Integer = 0
Public NpagineStampate As Integer = 0

'************************* FONT ******************************
Dim FontTitolo As New Font("Verdana", 20, FontStyle.Bold)
Dim FontRows As New Font("Verdana", 10, FontStyle.Regular)

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

'*********************************************************
'************************ VARIABILI **********************
Dim Y As Integer = 150 ' DISTANZA CIMA FOGLIO
Dim DistTitle As Integer = Y + 40 ' DISTANZA DA INTESTAZIONE A RISULTATI ORE
'
'*********************************************************
'***************** INTESTAZIONE FOGLIO **************

e.Graphics.DrawString("Croce Rossa Pontedassio", FontTitolo, Brushes.Black, 40, 50)
NrigheSuFoglio += 1
If DTPKa.Text = DTPKda.Text Then
e.Graphics.DrawString("Elenco ore del giorno " & DTPKa.Text, FontRows, Brushes.Black, 50, 90)
ElseIf DTPKda.Text <> DTPKa.Text Then
e.Graphics.DrawString("Elenco ore dal " & DTPKda.Text & " al " & DTPKa.Text, FontRows, Brushes.Black, 50, 90)
End If
NrigheSuFoglio += 1

If RDBoutputSoloTotali.Checked = True Then
e.Graphics.DrawString("VDS", FontRows, Brushes.Black, 40, Y) ' NOME
e.Graphics.DrawString("TOTALE", FontRows, Brushes.Black, 690, Y) ' SOMMA ORE
Else
e.Graphics.DrawString("VDS", FontRows, Brushes.Black, 40, Y) ' NOME
e.Graphics.DrawString("INIZIO TURNO", FontRows, Brushes.Black, 210, Y) ' DATA DI INIZIO
e.Graphics.DrawString("FINE TURNO", FontRows, Brushes.Black, 360, Y) ' DATA DI FINE
e.Graphics.DrawString("ORARIO", FontRows, Brushes.Black, 500, Y) ' ORA DI INIZIO
e.Graphics.DrawString("ORARIO", FontRows, Brushes.Black, 590, Y) ' ORA DI FINE
e.Graphics.DrawString("TOTALE", FontRows, Brushes.Black, 690, Y) ' SOMMA ORE
End If
e.Graphics.DrawRectangle(Pens.Black, 33, Y, 730, 18)
Y = DistTitle
NrigheSuFoglio += 1

'**************************************************************
'******************* LETTURA DA DATAGRID **********************

Do While NrigheSuFoglio < nMaxRighePerPagina

If NrigaInLettura = Nitems Then Exit Do

e.Graphics.DrawString(FRMvisualizzaOre.DGW.Rows(NrigaInLettura).Cells(0).Value, FontRows, Brushes.Black, 40, Y) ' NOME
e.Graphics.DrawString(FRMvisualizzaOre.DGW.Rows(NrigaInLettura).Cells(1).Value, FontRows, Brushes.Black, 210, Y) ' DATA DI INIZIO
e.Graphics.DrawString(FRMvisualizzaOre.DGW.Rows(NrigaInLettura).Cells(2).Value, FontRows, Brushes.Black, 360, Y) ' DATA DI FINE
e.Graphics.DrawString(FRMvisualizzaOre.DGW.Rows(NrigaInLettura).Cells(3).Value, FontRows, Brushes.Black, 500, Y) ' ORA DI INIZIO
e.Graphics.DrawString(FRMvisualizzaOre.DGW.Rows(NrigaInLettura).Cells(4).Value, FontRows, Brushes.Black, 590, Y) ' ORA DI FINE
' TRACCIO UNA DRAWLINE AL POSTO DI "---------"
If CStr(FRMvisualizzaOre.DGW.Rows(NrigaInLettura).Cells(5).Value) = "-----------" Then
e.Graphics.DrawLine(Pens.Black, 690, Y + 10, 740, Y + 10) ' LINEA DEL TOTALE
Else
e.Graphics.DrawString(FRMvisualizzaOre.DGW.Rows(NrigaInLettura).Cells(5).Value, FontRows, Brushes.Black, 690, Y) ' SOMMA ORE
End If

Y = Y + 20

NrigheSuFoglio += 1
NrigaInLettura += 1

Loop

NpagineStampate += 1

If NrigaInLettura = Nitems Then
e.Graphics.DrawString("Pagina " & NpagineStampate.ToString, FontRows, Brushes.Black, 690, 1120) ' "PAGINA TOT"
Exit Sub
End If

e.HasMorePages = True
NrigheSuFoglio = 0
e.Graphics.DrawString("Pagina " & NpagineStampate.ToString, FontRows, Brushes.Black, 690, 1120) ' "PAGINA TOT"

End Sub

Cosa succede?
Ringrazio come sempre in anticipo :)

daxdaxdax
21-08-2010, 14:55
up

jackk87
22-08-2010, 11:41
Ciao guarda questa discussione e fammi sapere se hai risolto http://www.hwupgrade.it/forum/showthread.php?t=1910285

:D

daxdaxdax
22-08-2010, 15:01
Grazie per la risposta jack

Ho risolto il problema "resettando" le variabili globali esterne di conteggio.

Private Sub PrintDocument1_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
NrigaInLettura = 0
NrigheSuFoglio = 0
NpagineStampate = 0
End Sub
:asd: