Print
button on the Print Dialog, I want to create an event on it so that I can record the printing transaction. Any help is highly appreciated. Thank you!on 04-02-2013 5:35 PM
How to create own button in CrystalReportViewer1?
I did created button, but when I run the report it doesn’t
show up. I am Vb 2008 and CrystalReport 8
I have two forms main and report. Report review works and
prints fine. I need to update in SQL if report is printed on which date.
I try this:
'find the print button
control and attach an event to it
For Each Obj As Object In myToolStrip.Items
If TypeOf Obj Is ToolStripButton Then
'Adding a handler for our propose
Dim b As ToolStripButton = CType(Obj, ToolStripButton)
If b.ToolTipText = "Print Report" Then
AddHandler CType(Obj, ToolStripButton).Click, AddressOf printButton_Click
End If
End If
Next
It never went to PrintButton_Click.
Now, I created
button name is PrintButton, but PrintButton doesn’t show up in CrystalReportViewer1
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As system.EventArgs) Handles PrintButton.Click
Dim dialog As New PrintDialog
dialog.UseEXDialog = True
dialog.AllowSomePages = True
If dialog.ShowDialog() = DialogResult.OK Then
Dim objRpt As ReportDocument = CType(Me.CrystalReportViewer1.ReportSource,
ReportDocument)
objRpt.PrintOptions.PrinterName = dialog.PrinterSettings.PrinterName
objRpt.PrintToPrinter(1, False, 0, 0)
PrintedDate()
Else
MessageBox.Show("print cancel")
Return
End If
End Sub
Can anyone out there help me Please?
I have been trying for two months.
Thank you
Hello Sunny
See if the following code snippet will help:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Drawing.Printing;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
CrystalReport1 cr;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ToolStrip ts;
ts = (ToolStrip)crystalReportViewer1 .Controls[3];
ToolStripButton printbutton = new ToolStripButton();
printbutton.Image = ts.Items[1].Image;
ts.Items.Remove(ts.Items[1]);
ts.Items.Insert(1, printbutton);
ts.Items[1].Click += new EventHandler(this.CaptureEvent);
cr = new CrystalReport1();
this.crystalReportViewer1.ReportSource = cr;
}
private void CaptureEvent(Object Sender, EventArgs e)
{
try
{ // Create a Print Dialog
PrintDialog printDialog1 = new PrintDialog();
// Create a Print Document
PrintDocument pd = new PrintDocument();
printDialog1.Document = pd;
printDialog1.ShowNetwork = true;
printDialog1.AllowSomePages = true;
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
MessageBox.Show("Print button has been selected !!!");
PrintReport(printDialog1.PrinterSettings.PrinterName);
}
else if (result == DialogResult.Cancel)
{
MessageBox.Show("Cancel button has been selected !!!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void PrintReport(string printerName)
{
// Select the printer.
cr.PrintOptions.PrinterName = printerName;
/* Print the report. Set the startPageN and endPageN
parameters to 0 to print all pages.*/
cr.PrintToPrinter(1, false, 0, 0);
}
}
}
Also see:
1493592 | How to create customized export options button for Crystal Reports winform viewer in Visual Studio .... | |
1400899 | How to customize the viewer options for a Crystal Reports .NET Viewer |
- Ludek
Follow us on Twitter
Got Enhancement ideas? Try the SAP Idea Place
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Content for 1493592:
Symptom
Clicking on the Export button of the viewer a choice of export formats is presented
The default export file format is an .rpt file
How to make the default export file format different?
How to remove certain export formats?
Resolution
Symptom
Clicking on the Export button of the viewer a choice of export formats is presented
The default export file format is an .rpt file
How to make the default export file format different?
How to remove certain export formats?
Resolution
Remove the viewer Export button from the toolstrip
Add a new Export button
On click event of the new Export button, present the user with custom export form
Use the following sample code
Private Sub frmReportPreview_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ts As ToolStrip
Dim currentExportButton As ToolStripButton
Dim newExportButton As ToolStripButton
' Replace the export button with our own export button so we can handle the event ourselves
ts = DirectCast(CRViewer.Controls(4), ToolStrip)
currentExportButton = DirectCast(ts.Items(0), ToolStripButton)
ts.Items.Remove(currentExportButton)
newExportButton = New ToolStripButton("", My.Resources.Export, AddressOf ExportButton_Click)
newExportButton.ToolTipText = "Export report to disk"
ts.Items.Insert(0, newExportButton)
End SubCreate windows form 'frmReportExport' that contains the export file types and their order, then use the following code:
Private Sub ExportButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim frmExport As frmReportExport
' Allow the user to specify options such as the name of the file and format before exporting.
frmExport = New frmReportExport
frmExport.Report = Report
frmExport.ShowDialog()
End SubThen use the code below to run the export from the custom report export windows form.
Report.ExportToDisk(exportFormat, fileExport.SelectedFilename)
Content for 1400899:
Symptom
A Microsoft Visual Studio .NET application uses the Crystal Reports for .NET SDK as the reporting development tool.
How do you customize the viewer options that appear in the Crystal Reports .NET Forms Viewer?
Resolution
The following properties can be set to change the Crystal Reports Viewer options:
ShowCloseButton, ShowExportButton, ShowGotoPageButon, ShowGroupTreeButton, ShowPageNavigateButton, ShowParameterPanelButton, ShowPrintButton, ShowRefreshButton, ShowTextSearchButton , ShowZoomButton
If these properties are set to true the buttons will appear on the viewer toolbar.
If additional or replacement functionality is required, set the appropriate button property to false to hide the button and place an additional element on the viewer.
It is not possible to extend the viewer toolbar.
how do you place an additional element on the viewer?
i know you can put true or false on these buttons: ShowCloseButton, ShowExportButton, ShowGotoPageButon, ShowGroupTreeButton, ShowPageNavigateButton, ShowParameterPanelButton, ShowPrintButton, ShowRefreshButton, ShowTextSearchButton , ShowZoomButton
Hi Ludek,
Your told me in your last posting (Ludek Uher Apr 2, 2013 10:57 PM )
“place an additional element on the viewer. It is not possible to extend the viewer toolbar.”
any help or your are waste of time?
you can email at sunny_caar@yahoo.com this is what I am trying to do
I created a report using vb.net 2008 and crystal report viewer. If user print the report, I need to record it. User click on print icon and print dialog show up with default print then user can click print or cancel. When the user clicks on the Print button on the Print Dialog, I want to create an event on it so that I can record the printing transaction. Any help is highly appreciated. Thank you! |
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.