The settings you are making for the report object will not be transferred to the viewer. E.g.; the two are quite independent. Your best option will be to add your own print button and then use your print code there. I have some basic steps on adding a button to the win viewer, but not WPF viewer - not sure if these will work for you:
How to add a customized print button to the Crystal Reports viewer control in Visual Studio .NET 2008 Windows application instead of using existing print button?
Resolution
Customized print button cna be added to the Crystal Reports Viewer by using ToolStrip.
Please refer to the following code to add a customized print button to the Crystal Reports Viewer control:
--------------------------------------------------------------------------------------------------------------------------------------------------
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