打印所有可滚动的文本框

时间:2012-10-21 20:21:55

标签: vb.net printing streamreader

在VB.NET中编程并有另一个小问题。我有TextBox使用StreamReader从txt文件填充。基本上我有一个打印选项,但只能打印TextBox中显示的内容,如果TextBox中有更多信息需要滚动,那么不打印(希望这有意义! )。有什么方法可以解决这个问题,所以打印出所有的信息吗?

这是我的代码:

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

1 个答案:

答案 0 :(得分:0)

How to print from a StreamReader on MSDN,向下滚动 - 有一个例子。从String打印可能需要稍加修改,然后您可以将TextBox.Text传递给它。或者只是使用AS IS并从StreamReader打印 - 无论如何应该得到相同的结果。