So I have this problem where I want to capture the print button in print report button in crystal report. How to do this?
The user will click the Print Report button in crystal report as shown in the first image, Print page will pop up as shown in the second image
So when the user will click the print button, I want to do something like put a message box and run a query in my vb project. How to capture the 'Print' button?
you can try this solution:
Private Sub Frm_stampa_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Hide default button
crv_stampa.ShowPrintButton = False
' New print button
For Each ctrl As Control In crv_stampa.Controls
If TypeOf ctrl Is Windows.Forms.ToolStrip Then
Dim btnNew As New ToolStripButton
btnNew.Text = "Print"
btnNew.ToolTipText = "Print"
btnNew.Image = My.Resources.stampa
btnNew.DisplayStyle = ToolStripItemDisplayStyle.Image
CType(ctrl, ToolStrip).Items.Insert(0, btnNew)
AddHandler btnNew.Click, AddressOf tsItem_Click
End If
Next
' ---------------------------------------------
End Sub
Private Sub tsItem_Click(sender As System.Object, e As System.EventArgs)
' Put your code here, before print
Dim PrintDialog As New PrintDialog()
If PrintDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
rpt.PrintOptions.PrinterName = PrintDialog.PrinterSettings.PrinterName
rpt.PrintToPrinter(PrintDialog.PrinterSettings.Copies, PrintDialog.PrinterSettings.Collate, PrintDialog.PrinterSettings.FromPage, PrintDialog.PrinterSettings.ToPage)
End If
End Sub