печать в VB.NET очень отличается от VB6. Вот пример кода, чтобы вы начали. Я бы рекомендовал вам рассмотреть «печать» в PDF вместо этого, например. используя библиотеку PDFSharp. PDFSharp больше похож на объект принтера VB6, и вы получаете PDF-документ в качестве дополнительного бонуса.
''' <summary>
''' Bare bones printout
''' </summary>
''' <remarks></remarks>
Public Class SimplePrintout
'USAGE:
'Dim spo As New SimplePrintout
'spo.PrintPreview()
Public Sub Print(Optional ByVal PrinterName As String = "")
'create the document object
Using pdcNew As New Printing.PrintDocument
'wire up event handlers to handle pagination
AddHandler pdcNew.PrintPage, AddressOf PrintPage
Using docOutput As Printing.PrintDocument = pdcNew
If PrinterName > "" Then
docOutput.PrinterSettings.PrinterName = PrinterName
End If
docOutput.Print()
End Using
End Using
End Sub
''' <summary>
''' Preview the Report on screen
''' </summary>
''' <remarks></remarks>
Public Sub PrintPreview(Optional ByVal Owner As Form = Nothing)
'create the document object
Using pdcNew As New Printing.PrintDocument
'wire up event handlers to handle pagination
AddHandler pdcNew.PrintPage, AddressOf PrintPage
Using ppvPreview As New PrintPreviewDialog
ppvPreview.Document = pdcNew
ppvPreview.FindForm.WindowState = FormWindowState.Maximized
If IsNothing(Owner) Then
ppvPreview.ShowDialog()
Else
ppvPreview.ShowDialog(Owner)
End If
End Using
End Using
End Sub
Sub PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim g As Graphics = e.Graphics 'shortcut
Dim x As Single = e.MarginBounds.Left '"Cursor" location
Dim y As Single = e.MarginBounds.Top '"Cursor" location
'g.DrawRectangle(Pens.Black, e.MarginBounds) '>>DEBUG: use this line to check margins
Dim fnt1 As New Font(System.Drawing.FontFamily.GenericSansSerif, 12, FontStyle.Regular, GraphicsUnit.Point)
g.DrawString("Simple printout line 1" & vbCrLf & " after CRLF", fnt1, Brushes.Black, x, y)
y += fnt1.GetHeight(g)
y += fnt1.GetHeight(g)
g.DrawString("Simple printout line 2", fnt1, Brushes.Black, x, y)
y += fnt1.GetHeight(g)
g.DrawString("Simple printout line 3", fnt1, Brushes.Black, x, y)
y += fnt1.GetHeight(g)
e.HasMorePages = False
End Sub
End Class