1

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

enter image description here

enter image description here

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?

1
  • Did you find out how to do this using c#? Commented Jan 11, 2019 at 15:39

3 Answers 3

2

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 
Sign up to request clarification or add additional context in comments.

Comments

0

You can do this ! Requeirements:C# (but you can change to VB.NET), Visual Studio 2015, WPF platform Where: [GenericReportViewer] that's it your component crystal report

private void GenericReportViewer_Loaded(object sender, RoutedEventArgs e){ //where: GenericReportViewer thats it name your crystal report component System.Windows.Controls.Button button = GenericReportViewer.FindName("btnPrint") as System.Windows.Controls.Button; button.Click += MyMethod; } private void MyMethod(object sender, RoutedEventArgs e){ //Your code here } 

1 Comment

I get errors when I have system.windows.forms library with system.windows. Adding just system.windows gives me errors on : Applications gives an ambigous reference since I am using application.startuppath.
0

If you don't want to add a custom button to the crviewer toolstrip, and just want to capture the native print button click event, you can try this:

Private Sub frmViewReport_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load For Each control In crViewer.Controls If TypeOf control Is ToolStrip Then For Each item In control.items If item.AccessibleName = "Imprimir Relatório" Then Dim prtButton As ToolStripButton = DirectCast(item, ToolStripButton) AddHandler prtButton.Click, AddressOf dostuff Exit For End If Next Exit For End If Next End Sub Private Sub dostuff() MsgBox("Print button was pressed") End Sub 

Note that item.AccessibleName is culture dependent

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.