Salve a tutti. Ho un problema con l'anteprima di stampa. Premetto ... riesco a stampare ma non a fare l'anteprima.
Vi spiego. Ho una griglia che carico attraverso un database. Attraverso questa griglia scorro i record fermandomi su quello che desidero stampare.
Il documento l'ho preformattato come dico io ma non riesco a fare l'anteprima.
In virtù del fatto che questo componente di preview non l'ho mai utilizzato ... sicuramente sbaglio qualcosa.
Di seguito posto quello che ho scritto.
Dell'anteprima mi esce il pannellino ma è privo di contenuto.

------------------------------------------------------------------------------------------
' The PrintDialog will print the document
' by handling the document's PrintPage event.

'Private stringToPrint As String

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

' Definizione del formato del testo
Dim CustomFormat As New StringFormat
Dim charactersOnPage As Integer = 0
Dim linesPerPage As Integer = 30
Dim printRectangle As New Rectangle(e.MarginBounds.Location.X, 370, e.MarginBounds.Width, 300)
Dim printRectangle1 As New Rectangle(e.MarginBounds.Location.X, 735, e.MarginBounds.Width, 300)
Dim StrTitoloProblema As String
Dim StrTitoloSoluzione As String
Dim StrUDT As String
Dim StrCASSA As String
Dim StrPriority As String
Dim StrOperatoreOpen As String
Dim StrOperatoreClose As String
Dim StrDataOpen As String
Dim StrDataClose As String
Dim StrTITOLO As String
Dim StrSerial As String
Dim Font As New System.Drawing.Font("Arial", 14, System.Drawing.FontStyle.Regular)
Dim Font1 As New System.Drawing.Font("Arial", 14, System.Drawing.FontStyle.Bold)
Dim Font2 As New System.Drawing.Font("Arial", 18, System.Drawing.FontStyle.Bold)
Dim Font3 As New System.Drawing.Font("Arial", 14, System.Drawing.FontStyle.Bold)
Dim Font4 As New System.Drawing.Font("Arial", 14, System.Drawing.FontStyle.Regular)
Dim Font5 As New System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Regular)
'Font Font = new Font("Times New Roman", 12, FontStyle.Bold);

'Dim printRectangle = New RectangleF(New PointF(e.MarginBounds.Left, e.MarginBounds.Top), New SizeF(e.MarginBounds.Width, e.MarginBounds.Height))
'Dim printRectangle1 = New RectangleF(New PointF(e.MarginBounds.X, e.MarginBounds.Y), New SizeF(e.MarginBounds.Width, e.MarginBounds.Height))
'Dim printRectangle2 As New Rectangle(170, 100, e.MarginBounds.Width, 100)

' Di seguito definisco la stringa che poi stampo poco dopo
StrTITOLO = "REPORT DI COLLAUDO"
StrUDT = "UDT:"
StrCASSA = "Cassa:"
StrOperatoreOpen = "Operatore Open:"
StrDataOpen = "Data Open:"
StrOperatoreClose = "Operatore Close:"
StrDataClose = "Data Close:"
StrPriority = "Priorità:"
StrTitoloProblema = "PROBLEMA:"
StrTitoloSoluzione = "SOLUZIONE:"
StrSerial = "SERIAL NUMBER"
' Qui stampo la stringa di cui sopra

' TITOLO
e.Graphics.DrawString(StrTITOLO, Font2, Brushes.Black, 270, 30)

' SERIAL
e.Graphics.DrawString(StrSerial, Font3, Brushes.Black, 560, 75)
e.Graphics.DrawString(Me.RichTextSerial2.Text, Font4, Brushes.Black, 560, 100)

' UDT
e.Graphics.DrawString(StrUDT, Font1, Brushes.Black, e.MarginBounds.Location.X, 130)
e.Graphics.DrawString(Me.RichTextUdt2.Text, Font, Brushes.Black, 275, 131)

' CASSA
e.Graphics.DrawString(StrCASSA, Font1, Brushes.Black, e.MarginBounds.Location.X, 155)
e.Graphics.DrawString(Me.RichTextCassa2.Text, Font, Brushes.Black, 275, 156)

' OPERATORE OPEN
e.Graphics.DrawString(StrOperatoreOpen, Font1, Brushes.Black, e.MarginBounds.Location.X, 180)
e.Graphics.DrawString(Me.RichTextOpOpen2.Text, Font, Brushes.Black, 275, 181)

' DATA OPEN
e.Graphics.DrawString(StrDataOpen, Font1, Brushes.Black, e.MarginBounds.Location.X, 205)
e.Graphics.DrawString(Me.LblOpenItem2.Text, Font, Brushes.Black, 275, 206)

' OPERATORE CLOSE
e.Graphics.DrawString(StrOperatoreClose, Font1, Brushes.Black, e.MarginBounds.Location.X, 230)
e.Graphics.DrawString(Me.RichTextOpClose2.Text, Font, Brushes.Black, 275, 231)

' DATA CLOSE
e.Graphics.DrawString(StrDataClose, Font1, Brushes.Black, e.MarginBounds.Location.X, 255)
e.Graphics.DrawString(Me.LblCloseItem2.Text, Font, Brushes.Black, 275, 256)

' PRIORITA'
e.Graphics.DrawString(StrPriority, Font1, Brushes.Black, e.MarginBounds.Location.X, 280)
e.Graphics.DrawString(Me.LblPriority.Text, Font, Brushes.Black, 275, 281)

CustomFormat.LineAlignment = StringAlignment.Center ' Allineamento verticale: centrale (Center) al margine superiore
CustomFormat.Alignment = StringAlignment.Near ' Allineamento orizzontale: vicino (near) al margine sinistro

' PROBLEMA
e.Graphics.DrawString(StrTitoloProblema, Font4, Brushes.Black, e.MarginBounds.Location.X, 340)
e.Graphics.DrawString(Me.TxtProblema2.Text, Font5, Brushes.Black, printRectangle, CustomFormat)
e.Graphics.DrawRectangle(Pens.Black, printRectangle)

' SOLUZIONE
e.Graphics.DrawString(StrTitoloSoluzione, Font4, Brushes.Black, e.MarginBounds.Location.X, 703)
e.Graphics.DrawString(Me.TxtSoluzione2.Text, Font5, Brushes.Black, printRectangle1, CustomFormat)
e.Graphics.DrawRectangle(Pens.Black, printRectangle1)

' Sets the value of charactersOnPage to the number of characters
' of stringToPrint that will fit within the bounds of the page.
e.Graphics.MeasureString(stringToPrint, Me.Font, e.MarginBounds.Size, _
StringFormat.GenericTypographic, charactersOnPage, linesPerPage)

'e.Graphics.DrawString(Me.RichTextCassa2.Text, Me.RichTextCassa2.Font, Brushes.Black, printRectangle2, CustomFormat)
'e.Graphics.DrawString(Me.TxtProblema2.Text, Me.TxtProblema2.Font, Brushes.Black, e.MarginBounds, CustomFormat)
'e.Graphics.DrawString(Me.TxtSoluzione2.Text, Me.TxtSoluzione2.Font, Brushes.Black, e.MarginBounds, CustomFormat)
' e.Graphics.DrawString(stringToPrint, Me.Font, Brushes.Black, _
' e.MarginBounds, StringFormat.GenericTypographic)

' Draw the content.
'e.Graphics.DrawString(text, printFont, System.Drawing.Brushes.Black, 10, 10)
'e.Graphics.DrawString(text1, printFont, System.Drawing.Brushes.Black, 10, 50)

End Sub

---------------------------------------------------------------------------------------
Private Sub RbtAnteprimaStampa_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles RbtAnteprimaStampa.Click

'ReadDocument()
PrintPreviewDialog.Document = PrintDocument1
PrintPreviewDialog.ShowDialog()
End Sub 'Me.Dispose()

---------------------------------------------------------------------------------------