printer object to do text report

D

David

I have VB6 app that generates a report using the Printer object. It
basically was an old text report that i generated using Print# statements.

I am wondering if the Printer object has changed significantly in vb.net and
whether to consider using some other tool.

The report grabs data from a database but I do a lot of processing of the
data and generate alot of calculations before I generate my report.
 
H

Herfried K. Wagner [MVP]

David said:
I have VB6 app that generates a report using the Printer object. It
basically was an old text report that i generated using Print# statements.

I am wondering if the Printer object has changed significantly in vb.net
and whether to consider using some other tool.

How to send raw data to a printer by using Visual Basic .NET
<URL:http://support.microsoft.com/?scid=kb;EN-US;322090>
 
S

SurturZ

Printing under VB.NET is completely different to VB6.

You'll need a day or two to learn the new way of doing things. It's more
complicated but gives you better control of the printer and allows print
preview very easily.

If you want a quick fix, use this object:

''' <summary>
''' Bare bones printout
''' </summary>
''' <remarks></remarks>
Public Class SimplePrintout
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)
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

Put your printing code in PrintPage(), then in your command button (or
whatever):
Dim p As New SimplePrintout
p.PrintPreview
 
J

James Parsly

You can download a power pack for visual studio 2005 that gives you a
printer object that works
almost exactly the way it worked in vb6.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top