如何在Crystal Report中显示打印对话框? [英] How to show print dialog in Crystal Report?
本文介绍了如何在Crystal Report中显示打印对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要将 Crystal报表
直接打印到打印机。目前我正在导出 PDF
。但我的客户希望这个直接去打印机。如何显示打印对话框
点击打印按钮将报告直接打印到打印机。
比如:我使用C#和asp.net作为我的项目。
谢谢。
解决方案
尝试以下代码
private void Button1_Click(object sender,EventArgs e)
{
CrystalReport1 report1 = new CrystalReport1();
PrintDialog dialog1 = new PrintDialog();
report1.SetDatabaseLogon(username,password);
dialog1.AllowSomePages = true;
dialog1.AllowPrintToFile = false;
if(dialog1.ShowDialog()== System.Windows.Forms.DialogResult.OK)
{
int copies = dialog1.PrinterSettings.Copies;
int fromPage = dialog1.PrinterSettings.FromPage;
int toPage = dialog1.PrinterSettings.ToPage;
bool collate = dialog1.PrinterSettings.Collate;
report1.PrintOptions.PrinterName = dialog1.PrinterSettings.PrinterName;
report1.PrintToPrinter(copies,collate,fromPage,toPage);
}
report1.Dispose();
dialog1.Dispose();
}
您将不得不更改用户名和密码
此代码可以是仅用于服务器端打印。
I want to print my Crystal report
direct to the printer. Currently I am having the export to PDF
. But my client want this to go to Printer directly. How can I show the Print Dialog
on click of Print Button to Print the report directly to Printer.
I would like to mention: I am using C# and asp.net for my project.
Thank you.
解决方案
Try the following code
private void Button1_Click(object sender, EventArgs e)
{
CrystalReport1 report1 = new CrystalReport1();
PrintDialog dialog1 = new PrintDialog();
report1.SetDatabaseLogon("username", "password");
dialog1.AllowSomePages = true;
dialog1.AllowPrintToFile = false;
if (dialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
int copies = dialog1.PrinterSettings.Copies;
int fromPage = dialog1.PrinterSettings.FromPage;
int toPage = dialog1.PrinterSettings.ToPage;
bool collate = dialog1.PrinterSettings.Collate;
report1.PrintOptions.PrinterName = dialog1.PrinterSettings.PrinterName;
report1.PrintToPrinter(copies, collate, fromPage, toPage);
}
report1.Dispose();
dialog1.Dispose();
}
you will have to change the "username" and the "password" with the credentials of your database.
EDIT
This code can be used for server side printing only.
这篇关于如何在Crystal Report中显示打印对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文