Imports System.Drawing.Printing
Imports System.IO
Public ClassForm1
Dim inputStream As StreamReader
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) HandlesButton1.Click
Dim pd As NewPrintDocument
Try
inputStream = NewStreamReader("D:\print.txt")
AddHandler pd.PrintPage,AddressOf Me.pd_PrintPage
pd.Print()
Catch ex As Exception
MsgBox("Error:"& ex.Message)
Finally
inputStream.Close()
End Try
End Sub
Private Sub pd_PrintPage(ByVal sender As Object,ByVal ev As PrintPageEventArgs)
Dim ypos As Integer =ev.MarginBounds.Top
Dim count As Integer
Dim currentLine As String
Dim xpos As Integer =ev.MarginBounds.Left
Dim f As NewFont("Times", 11)
Dim lineHeight As Integer =f.GetHeight(ev.Graphics)
Dim numOfLines As Integer =ev.MarginBounds.Height / lineHeight
Do Until count = numOfLines
currentLine = inputStream.ReadLine
If currentLine Is NothingThen
Exit Do
End If
ev.Graphics.DrawString(currentLine, f, Brushes.Black, xpos,ypos)
ypos += lineHeight
count += 1
If Not currentLine Is NothingThen
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
Loop
End Sub
End Class
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。