如何在 Crystal Report 中显示打印对话框?

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)