我想将我的 Crystal 报告
直接打印到打印机.目前我正在导出到 PDF
.但我的客户希望它直接进入打印机.如何在单击打印按钮时显示 Print Dialog
以将报告直接打印到打印机.
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.
我想提一下:我正在为我的项目使用 C# 和 asp.net.
I would like to mention: I am using C# and asp.net for my project.
谢谢.
试试下面的代码
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.
编辑
此代码仅可用于服务器端打印.
这篇关于如何在 Crystal Report 中显示打印对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!