Print the content of a listview

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The Print() method used in my vb .net 2003 program abort with a
"Descripteur non valide" and i don't know why.

Following the part of my code :

Friend WithEvents Papier As System.Drawing.Printing.PrintDocument
Me.Papier = New System.Drawing.Printing.PrintDocument
Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click
Try
Papier.Print()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Problème d'impression
!")
End Try
End Sub

Private Sub Papier_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles Papier.PrintPage
e.Graphics.DrawString(Me.Text, New Font("Helvetica narrow", 12,
FontStyle.Bold), Brushes.Black, 160, 4)
e.Graphics.DrawString("Section", New Font("Helvetica narrow", 10,
FontStyle.Bold), Brushes.Black, 14, 50)
e.Graphics.DrawString("Rubrique", New Font("Helvetica narrow", 10,
FontStyle.Bold), Brushes.Black, 180, 50)
......
 
Hi Bernalin,

I changed your code slightly and it works for me.

Public Class Form1
Friend WithEvents Papier As New System.Drawing.Printing.PrintDocument

Private Sub cmdPrint_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdPrint.Click

Try
Papier.Print()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Problème
d'impression!"
End Try
End Sub

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

e.Graphics.DrawString(Me.Text, New Font("Helvetica narrow", _
12, FontStyle.Bold), Brushes.Black, 160, 4)
e.Graphics.DrawString("Section", New Font("Helvetica narrow", _
10, FontStyle.Bold), Brushes.Black, 14, 50)
e.Graphics.DrawString("Rubrique", New Font("Helvetica narrow", _
10, FontStyle.Bold), Brushes.Black, 180, 50)
End Sub

End Class

Hope this helps.

Martin.
 
Back
Top