Click here to Skip to main content
11,431,307 members (69,980 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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?.


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 2-Jan-13 20:37pm
raymee447
Edited 2-Jan-13 20:42pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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


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
  Permalink  

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



Advertise | Privacy | Mobile
Web02 | 2.8.150428.2 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100