View Single Post
  #1 (permalink)  
Old 01-08-2009, 11:48 AM
Blesson Blesson is offline
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jan 2009
Age: 23
Posts: 18
Reputation: 17
Blesson is on a distinguished programming path ahead
Default printing the contents of a text box?

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.

Code:
    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 JohnH; 01-08-2009 at 6:07 PM. Reason: thread split, different topic
Reply With Quote