Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi expert, i need some guideline on how to achieve this.

I have created printpreviewdialog in button_click event. But the problem
is, im able to preview only one documents at a time. Is it posible for me
to call the second printpageevents as second page in my printpriviewdialog?.


VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            
        Dim prn As New Printing.PrintDocument
        Dim Preview As New PrintPreviewDialog
        AddHandler prn.PrintPage, AddressOf _Invoice
        Preview.Document = prn
        Preview.PrintPreviewControl.Zoom = 1
        Preview.Showdialog

    End Sub


Private Sub _Invoice(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)

args.Graphics.PageUnit = GraphicsUnit.Millimeter
args.Graphics.DrawString("Invoice", New Font("Arial Narrow", 12, FontStyle.Bold), Brushes.Black, 10, 5)

End Sub


Private Sub _DO(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)

args.Graphics.PageUnit = GraphicsUnit.Millimeter
args.Graphics.DrawString("DO", New Font("Arial Narrow", 12, FontStyle.Bold), Brushes.Black, 10, 5)

End Sub
Posted
Updated 2-Jan-13 19:42pm
v2

1 solution

After some research, I have done this and works for me.


VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Preview As New PrintPreviewDialog
        Dim prn As New Printing.PrintDocument
        AddHandler prn.PrintPage, AddressOf _Invoice
        With Preview
            .Document = prn
            .WindowState = FormWindowState.Maximized
            .Document.DefaultPageSettings.PaperSize = New System.Drawing.Printing.PaperSize("A4", 827, 1169)
            .PrintPreviewControl.Zoom = 1
            .Document = prn
            .ShowDialog()
        End With
    End Sub

    Private Sub _Invoice(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)
        args.Graphics.DrawString("INVOICE", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 20, 20)
        args.HasMorePages = True
        Dim prn As Printing.PrintDocument = sender
        RemoveHandler prn.PrintPage, AddressOf _Invoice
        AddHandler prn.PrintPage, AddressOf _DO
        Exit Sub
    End Sub

    Private Sub _DO(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)
        args.Graphics.DrawString("D.O", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 20, 20)
    End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900