Question : How to print a new page on vb.net

Hi,

I want to know how to print out not only one page?
Please help me to enhance my code to print out
first page is TextBox1.Text
second page is def abc

What should I do?

Thank you!

Francis SZE
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
Imports System.Drawing.Printing

Public Class Form2
    Private PrintPageSettings As New PageSettings

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim PrintDoc As New PrintDocument
            AddHandler PrintDoc.PrintPage, AddressOf Me.PrintText
            PrintDoc.Print()

        Catch ex As Exception
            MessageBox.Show("Sorry-- there is a problem printing", ex.ToString)
        End Try
    End Sub

    Private Sub PrintText(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
        '        Private printpagesettings As New PageSettings
        ev.Graphics.DrawString(TextBox1.Text, New Font("Arial", 11, FontStyle.Regular), Brushes.Black, 120, 120)
        ev.HasMorePages = True

        ev.Graphics.DrawString("def abc", New Font("Arial", 11, FontStyle.Regular), Brushes.Black, 120, 120)
        ev.HasMorePages = False
    End Sub


End Class

Answer : How to print a new page on vb.net

modify this code as per your need
But first run this to verify your output


ev.HasMorePages is evaluated only after that events gets complete.
If ev.HasMorePages = True then that event is fired again
and on next run ev.HasMorePages = False will stop firing that event.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
dim isFirstRun as boolean = True
Private Sub PrintText(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
        '        Private printpagesettings As New PageSettings

If isFirstRun Then
        ev.Graphics.DrawString(TextBox1.Text, New Font("Arial", 11, FontStyle.Regular), Brushes.Black, 120, 120)
        ev.HasMorePages = True
isFirstRun = False
Else
        ev.Graphics.DrawString("def abc", New Font("Arial", 11, FontStyle.Regular), Brushes.Black, 120, 120)
        ev.HasMorePages = False
End If
    End Sub
Random Solutions  
 
programming4us programming4us