Programming in VB.NET and have another slight issue. I have a TextBox that is populated from a txt file using a StreamReader. Basically I have a print option but can only print what is shown in the TextBox, if there is more info in the TextBox further down that needs to be scrolled this is not printed (hope that makes sense!). Is there any way I get get around this so all of the information is printed?
Here’s my code:
Imports System.Drawing.Printing
Public Class JobList
Private Sub JobList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objReader As New System.IO.StreamReader("C:\test\JobLog.txt", True)
txtJL.Text = objReader.ReadToEnd
objReader.Close()
End Sub
Private Sub printText(ByVal sender As System.Object, ByVal ev As PrintPageEventArgs)
Dim font As New Font("Arial", 16, FontStyle.Regular)
ev.Graphics.DrawString(txtJL.Text, font, Brushes.Black, 100, 100)
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim printDoc As New PrintDocument
AddHandler printDoc.PrintPage, AddressOf Me.printText
printDoc.Print()
End Sub
End Class
How to print from a
StreamReaderon MSDN, scroll down – there is an example. It may need a slight modification to print from aString, then you can passTextBox.Textinto it. Or just use AS IS and print fromStreamReader– should get same results anyway.