Click here to Skip to main content
15,920,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I Check Print Preview Dialog's print Button Event?

For Example :

I wanna print the page only one time and when second time user click on Print Preview Dialog's Print Button then I will restrict the user.
Posted
Updated 30-Aug-18 3:43am
v2
Comments
Dave Kreskowiak 28-Oct-13 13:09pm    
This sounds incredibly stupid. What if the printer "eats" the job because of some hardware failure and it needs to be reprinted??
ridoy 28-Oct-13 13:22pm    
totally agree.

1 solution

Really cant get your Idea behind this.. As Dave Kreskowiak says about the possible errors of your case. But I am working on a project where I need PrintPreviewDialog and I need to select a printer instead of direct print of document when Print option of PrintPreviewDialog is clicked. So I managed to do
1. manipulate Print Toolstrip of the PrintPreviewDialog
2. Add a Handler to PrintDocument.PrintPage event and PrintPreview.PrintClick event
VB
 Private Sub Print_btn_Click(sender As Object, e As EventArgs) Handles Print_btn.Click
        Dim b As New ToolStripButton
        b.Image = CType(PrintPreviewDialog1.Controls(1), ToolStrip).ImageList.Images(0)
        b.ToolTipText = "Print"
        b.DisplayStyle = ToolStripItemDisplayStyle.Image
        AddHandler b.Click, AddressOf PrintPreview_PrintClick
        CType(PrintPreviewDialog1.Controls(1), ToolStrip).Items.RemoveAt(0)
        CType(PrintPreviewDialog1.Controls(1), ToolStrip).Items.Insert(0, b)
        AddHandler PrintDocument1.PrintPage, AddressOf PrintDocument1_PrintPage
        PrintPreviewDialog1.Document = PrintDocument1
        PrintDocument1.OriginAtMargins = False
        PrintPreviewDialog1.ShowDialog()
    End Sub

Private Sub PrintPreview_PrintClick(sender As Object, e As EventArgs)
        Try
            PrintDialog1.Document = PrintDocument1
            If PrintDialog1.ShowDialog() = DialogResult.OK Then
                PrintDocument1.Print()
            End If
        Catch ex As Exception
        End Try
        
    End Sub

    Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Me.BackgroundImage = WindowsApp1.My.Resources.Resources.WhiteBackground
        Dim print_bmp As Bitmap = GetClientareaImage(Me)
        e.Graphics.DrawImage(print_bmp, 0, 0)
    End Sub


I need to print the image of form's client area. So I write the function "GetClientareaImage()" which has no Relation to this solution. Thats why I am not posting it.
 
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