How to print text in multiline textbox ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fniles

    How to print text in multiline textbox ?

    I am using VB.NET 2008.
    I have a multiline textbox on the form that I would like to print when the
    user click on the "Print" button.
    With my codes below, when the text are in more than 1 page (say 3 pages) of
    the textbox, when it prints the text in the text box, the 2nd and 3rd pages
    are printed on the same page with the 1st page.
    So, instead of printing 3 pages, it prints 1 page with the text from page 2
    and 3 are printed on top of each other.
    Please let me know how I can do it correctly.
    Thank you.

    Private Sub cmdPrint_Click( ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles cmdPrint.Click
    prnDoc.DefaultP ageSettings.Lan dscape = True
    Dim strText As String = txtLog.Text
    myReader = New StringReader(st rText)
    prnDoc.Print()
    End Sub

    Private Sub prnDoc_PrintPag e(ByVal sender As Object, ByVal e As
    System.Drawing. Printing.PrintP ageEventArgs) Handles prnDoc.PrintPag e
    Dim linesPerPage As Single = 0
    Dim yPosition As Single = 0
    Dim count As Integer = 0
    Dim leftMargin As Single = e.MarginBounds. Left
    Dim topMargin As Single = e.MarginBounds. Top
    Dim line As String = Nothing
    Dim printFont As Font = txtLog.Font
    Dim myBrush As New SolidBrush(Colo r.Black)

    linesPerPage = e.MarginBounds. Height /
    printFont.GetHe ight(e.Graphics )
    While count < linesPerPage
    line = myReader.ReadLi ne()
    If (line Is Nothing) Then
    Exit While
    Else
    yPosition = topMargin + count *
    printFont.GetHe ight(e.Graphics )
    e.Graphics.Draw String(line, printFont, myBrush, leftMargin,
    yPosition, New StringFormat())
    count += 1
    If count >= linesPerPage Then
    e.HasMorePages = True
    count = 0
    End If
    End If
    End While
    e.HasMorePages = False
    myBrush.Dispose ()


  • fniles

    #2
    Re: How to print text in multiline textbox ?

    Never mind.
    I got my answer (thanks to a posting by Andy on www.vbforums.com).
    This is how my code look like now:

    Private Sub prnDoc_PrintPag e(ByVal sender As Object, ByVal e As
    System.Drawing. Printing.PrintP ageEventArgs) Handles prnDoc.PrintPag e
    Dim linesPerPage As Single = 0
    Dim yPosition As Single = 0
    Dim count As Integer = 0
    Dim leftMargin As Single = e.MarginBounds. Left
    Dim topMargin As Single = e.MarginBounds. Top
    Dim line As String = Nothing
    Dim printFont As Font = txtLog.Font
    Dim myBrush As New SolidBrush(Colo r.Black)
    linesPerPage = e.MarginBounds. Height /
    printFont.GetHe ight(e.Graphics )
    While count < linesPerPage
    line = myReader.ReadLi ne()
    If (line Is Nothing) Then
    Exit While
    Else
    yPosition = topMargin + count *
    printFont.GetHe ight(e.Graphics )
    e.Graphics.Draw String(line, printFont, myBrush, leftMargin,
    yPosition, New StringFormat())
    count += 1
    End If
    End While
    If Not (line Is Nothing) Then
    e.HasMorePages = True
    Else
    e.HasMorePages = False
    End If
    myBrush.Dispose ()

    "fniles" <fniles@pfmail. comwrote in message
    news:%23WeuVVxy IHA.3680@TK2MSF TNGP05.phx.gbl. ..
    >I am using VB.NET 2008.
    I have a multiline textbox on the form that I would like to print when the
    user click on the "Print" button.
    With my codes below, when the text are in more than 1 page (say 3 pages)
    of the textbox, when it prints the text in the text box, the 2nd and 3rd
    pages are printed on the same page with the 1st page.
    So, instead of printing 3 pages, it prints 1 page with the text from page
    2 and 3 are printed on top of each other.
    Please let me know how I can do it correctly.
    Thank you.
    >
    Private Sub cmdPrint_Click( ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles cmdPrint.Click
    prnDoc.DefaultP ageSettings.Lan dscape = True
    Dim strText As String = txtLog.Text
    myReader = New StringReader(st rText)
    prnDoc.Print()
    End Sub
    >
    Private Sub prnDoc_PrintPag e(ByVal sender As Object, ByVal e As
    System.Drawing. Printing.PrintP ageEventArgs) Handles prnDoc.PrintPag e
    Dim linesPerPage As Single = 0
    Dim yPosition As Single = 0
    Dim count As Integer = 0
    Dim leftMargin As Single = e.MarginBounds. Left
    Dim topMargin As Single = e.MarginBounds. Top
    Dim line As String = Nothing
    Dim printFont As Font = txtLog.Font
    Dim myBrush As New SolidBrush(Colo r.Black)
    >
    linesPerPage = e.MarginBounds. Height /
    printFont.GetHe ight(e.Graphics )
    While count < linesPerPage
    line = myReader.ReadLi ne()
    If (line Is Nothing) Then
    Exit While
    Else
    yPosition = topMargin + count *
    printFont.GetHe ight(e.Graphics )
    e.Graphics.Draw String(line, printFont, myBrush, leftMargin,
    yPosition, New StringFormat())
    count += 1
    If count >= linesPerPage Then
    e.HasMorePages = True
    count = 0
    End If
    End If
    End While
    e.HasMorePages = False
    myBrush.Dispose ()
    >
    >

    Comment

    Working...