printing the contents of a text box?

Blesson

Member
Joined
Jan 2, 2009
Messages
18
Programming Experience
Beginner
now i am printing the contents of a text box, my problem is i am able to print only one page . i want to know how to test whether it has execeed one page and trigger the print page event again for the next pages.


i know that we have to use the e.hasmorepages=true but i dont know what the if condition will be.

my code is shown below.

VB.NET:
    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        Dim font As New Font("Verdana", 14)
        Dim PrintAreaHeight, PrintAreaWidth, marginLeft, marginTop As Int32
        With PrintDocument1.DefaultPageSettings

            'initializing local variables that contain the bounds of the printing area rectangle
            PrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
            PrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
            marginLeft = .Margins.Left
            marginTop = .Margins.Top

            ' if the user selects landscape mode, swap the printing area height and width
            If PrintDocument1.DefaultPageSettings.Landscape Then
                Dim intTemp As Int32
                intTemp = PrintAreaHeight
                PrintAreaHeight = PrintAreaWidth
                PrintAreaWidth = intTemp
                ' if the user selects landscape mode, swap the printing area height and width
            End If

           ' initializing the rectangle structure that defines the printing area
            Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, PrintAreaWidth, PrintAreaHeight)
            ' calculating the total number of lines in the document based on the height of
            ' the printing area and the height of the font
            Dim intLineCount As Int32 = CInt(PrintAreaHeight / font.Height)
            'instantiating the StringFormat class, which encapsulates text layout information
            Dim fmt As New StringFormat(StringFormatFlags.LineLimit)

            ' print the text to the page
            e.Graphics.DrawString(Mid(TextBox1.Text, 1), font, Brushes.Black, rectPrintingArea, fmt)

            'HasMorePages tells the printing module whether another PrintPage event should be fired
            e.HasMorePages = False
        End With

    End Sub




i want to know wat will be the criteria in the if condition

if(..........) then
e.hasmorepages=true
end if


Thanks
 
Last edited by a moderator:
hi,
I checked it out but that is not what i am looking for . i would like to know how the print more than one page . i mean how to check if the no of lines have execeed the page limit and call the print page event again.

thanks
 
How can it not be what you look for? The code you posted is a rip-out from that class - same code, same variable names, only missing a few lines of it. That class prints more than one page. You should copy it in full, use it, and study the code to learn from it.
 
sorry John I have not seen the link to the code. Howeve after you said looked again and found it. but i cannot the below code.

Public Sub New(ByVal Text As String)
' Sets the file stream
MyBase.New()
strText = Text
End Sub

1. I have no idea what this code does
2. Why is it used


Thanks.
I mean i dont know the concept of using public sub new.
 
I posted the sample how to use the class and the constructor, look again. I see now the article also has a usage sample below.
 
Follow the link in post 2.
 
Back
Top