on 09-23-2014 12:41 AM
Hi, I used CrystalReportViewer in Visual Studio 2013 to show report on Web app. The report works fine, but when I click "Print" button to print this report, it shows the dialog "Print to PDF" to Export. How to get "Print" dialog.
Thank you very much for any idea and help.
Regards,
Qin
Alternatively, create your own print dialog and place that under your own button:
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);
}
}
}
- Ludek
Senior Support Engineer AGS Product Support, Global Support Center Canada
Follow us on Twitter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In Visual Studio - CrystalReportViewer Control properties - set the 'PrintMode' property to 'ActiveX'.
By default the property is set to 'PDF' thats why the print to pdf pops up.
- Bhushan
Senior Engineer
SAP Active Global Support
Follow us on Twitter
Got Enhancement ideas? Try the SAP Idea Place
Getting started and moving ahead with Crystal Reports .NET applications.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.