How to show print dialog in Crystal Report?(如何在 Crystal Report 中显示打印对话框?)
问题描述
我想将我的 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 中显示打印对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Crystal Report 中显示打印对话框?


- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 使用 rss + c# 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01