Home > Back-end >  How can i raised the event for PrintPage?
How can i raised the event for PrintPage?

Time:07-12

how can i raised the event for print page in form 2 while im in form 1

this is the event i want to raised

  Public Sub PrintDocument1_PrintPage_1(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim dm As New Bitmap(Me.Panel1.Width, Me.Panel1.Height)
        Panel1.DrawToBitmap(dm, New Rectangle(0, 0, Me.Panel1.Width, Me.Panel1.Height))
        e.Graphics.DrawImage(dm, 0, 0)

        Dim aPS As New PageSetupDialog
        aPS.Document = PrintDocument1

    End Sub

i want to be able to raised that event here

Public Sub printall()
        If txtempname.Items.Count = 0 Then
            MessageBox.Show("There is no Record to Print")
        Else
            For i = 0 To txtempname.Items.Count - 1
                txtempname.SelectedIndex = i
                getEmployeeInfo()
                getattendance()
                getDeductions()
                getExtraDeductions()
                getLoans()
                calculate()
                printallnote()
                PrintPayslip.payslip()

                'Raised PrintPage event here

                PrintPayslip.print()
                PrintPayslip.Close()
            Next
        End If
    End Sub

CodePudding user response:

You call Print on your PrintDocument. That will raise the BeginPrint event first and then the PrintPage event. As long as you set e.HasMorePages to True in the event handler, the PrintPage event will continue to be raised. Finally, the EndPrint event will be raised.

Alternatively, if you call ShowDialog on a PrintPreviewDialog, the same events will be raised when the user clicks the Print button.

  • Related