|
-
Aug 27th, 2002, 02:51 PM
#1
Thread Starter
Junior Member
Printing in .Net
Does anyone know how to print. Every quickstart tutorial I tried failed. Printing in .Net cannot be as hard as it has been so far. I even found things that were not part of classes.
All I want to do is print a file. Even the books I have and the websites out there leave the answer out of the explanation. They explain what printing is. I know what I want it to do, I just need to figure out how.
I'm thinking 1.Load Printer objects - 2.Load document - 3.Select printer - 4.Print document.
Based on the info out there printing is an obscure task and everyone uses felt tip pens and have monks to make hand copies but I would have to guess that somebody else has tried to print something in VB.Net.
-
Aug 27th, 2002, 07:04 PM
#2
Registered User
VB Code:
Private StreamToPrint As IO.StreamReader
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim LinesPerPage As Single = e.MarginBounds.Height / PrintFont.GetHeight(e.Graphics)
Dim Line As String = Nothing, count As Integer, yPos As Single = 0
For count = 0 To LinesPerPage - 1
Line = StreamToPrint.ReadLine
If Line Is Nothing Then Exit For
yPos = e.MarginBounds.Top + count * PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString(Line, PrintFont, Brushes.Black, e.MarginBounds.Left, yPos, New StringFormat())
Next
If Not (Line Is Nothing) Then e.HasMorePages = True
End Sub
Private Sub MenuItemPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemPrint.Click
StreamToPrint = New IO.StreamReader("temp.xml")
PrintDialog1.Document = PrintDocument1
PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
PrintDialog1.AllowSomePages = True
If PrintDialog1.ShowDialog = DialogResult.OK Then
PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
PrintDocument1.Print()
If Not (StreamToPrint Is Nothing) Then
StreamToPrint.Close()
End If
End If
End Sub
-
Aug 28th, 2002, 06:53 AM
#3
Thread Starter
Junior Member
printing
Thanks jkw119,
If anyone is interested, this code works. I found some similiar code last night and tried it out. Looks like I will be using it a lot for priniting reports after performing functionality tests so I tossed the code into a class to make life easier.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|