Printing from classes and modules

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

Guest

Hi there

Ive got a class which i use for alot of data storage in my program and id like to add a print routine to this class so that i can print out a formatted version of all the data. I just cant seem to work out how to create a document in the class and then link the preview and print dialogs to it. Does anyone have any tips or know of tutorials which show how to do this with out placing controls on a form. Hope someone can help out

Regard

James Procto

http://www.ebmis.co.u
 
Hi,

I would add a printdocument variable to print from a class

Dim WithEvents m_pdMyDoc As System.Drawing.Printing.PrintDocument



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

Dim fnt As New Font(FontFamily.GenericSansSerif, FontStyle.Regular)

e.Graphics.DrawString("Test", fnt, Brushes.Black, 0, 0)

End Sub

Public Sub PrintOut()

m_pdMyDoc.Print()

End Sub



Ken

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

James Proctor said:
Hi there,

Ive got a class which i use for alot of data storage in my program and id
like to add a print routine to this class so that i can print out a
formatted version of all the data. I just cant seem to work out how to
create a document in the class and then link the preview and print dialogs
to it. Does anyone have any tips or know of tutorials which show how to do
this with out placing controls on a form. Hope someone can help out.
 
* "=?Utf-8?B?SmFtZXMgUHJvY3Rvcg==?= said:
Ive got a class which i use for alot of data storage in my program and
id like to add a print routine to this class so that i can print out a
formatted version of all the data. I just cant seem to work out how to
create a document in the class and then link the preview and print
dialogs to it. Does anyone have any tips or know of tutorials which show
how to do this with out placing controls on a form. Hope someone can
help out.

See:

<http://www.mvps.org/dotnet/dotnet/samples/printing/downloads/PrintFramework.zip>
 
Ok ive got this code now, but when i call the print preview sub it shows the print preview dialog but says there are no pages in this document. Whys this? Am i doing something stupid that im missing out on. Hope you can help. Thanks for your help so far.

JP

Dim WithEvents PrintDocument1 As Drawing.Printing.PrintDocument

Public Sub PrintPreview()
Dim PrintDocPreview As New PrintPreviewDialog
With PrintDocPreview
.Document = Me.PrintDocument1
.ShowDialog()
End With
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim Font As New Font("Arial", 24, FontStyle.Bold)
Dim XPos, YPos As Single
Dim Lineheight As Single = 50
XPos = e.MarginBounds.Left
YPos = e.MarginBounds.Top
e.Graphics.DrawString("Kit ID:", Font, Brushes.Black, XPos, YPos)
YPos = 100
e.Graphics.DrawString(Trim(Me.ID), Font, Brushes.Black, XPos, YPos)
End Sub
 
Hi,

Dim WithEvents PrintDocument1 As New Drawing.Printing.PrintDocument

Ken
---------------------
James Proctor said:
Ok ive got this code now, but when i call the print preview sub it shows
the print preview dialog but says there are no pages in this document. Whys
this? Am i doing something stupid that im missing out on. Hope you can help.
Thanks for your help so far.
JP

Public Sub PrintPreview()
Dim PrintDocPreview As New PrintPreviewDialog
With PrintDocPreview
.Document = Me.PrintDocument1
.ShowDialog()
End With
End Sub

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