adamdavies
Programmer
I have used the example off the web for printing a textfile to a network printer.
This does not seem to work, i dont think it can find the network printer by default.
does anybody know what i need to be doing.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
streamToPrint = New StreamReader("test.txt"
Try
printFont = New Font("Arial", 10)
Dim pd As PrintDocument = New PrintDocument
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()
Finally
streamToPrint.Close()
End Try
Catch ex As Exception
lblMessage.Text = ex.Message
End Try
End Sub
'////////
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line As String = Nothing
'Calculate the number of lines per page
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
'Print each line of the file
While count < linesPerPage
line = streamToPrint.ReadLine()
If line Is Nothing Then
Exit While
End If
yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat)
count += 1
End While
'If more lines exist, print another page
If Not (line Is Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub
thanks
adam
This does not seem to work, i dont think it can find the network printer by default.
does anybody know what i need to be doing.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
streamToPrint = New StreamReader("test.txt"
Try
printFont = New Font("Arial", 10)
Dim pd As PrintDocument = New PrintDocument
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()
Finally
streamToPrint.Close()
End Try
Catch ex As Exception
lblMessage.Text = ex.Message
End Try
End Sub
'////////
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line As String = Nothing
'Calculate the number of lines per page
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
'Print each line of the file
While count < linesPerPage
line = streamToPrint.ReadLine()
If line Is Nothing Then
Exit While
End If
yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat)
count += 1
End While
'If more lines exist, print another page
If Not (line Is Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub
thanks
adam