更改 ReportViewer C# 中打印按钮的行为 [英] Change behaviour of Print button in ReportViewer C#
问题描述
我正在使用 ReportViewer,我想打印我的报告.
I am using a ReportViewer and I would like to print my report.
当我单击打印按钮时,会打开一个对话框.与此类似.
When I click on the print button, a dialog box opens. It is similar to this.
我希望我的程序跳过此对话框并选择默认打印机.
I would like my program to skip this dialog and choose the default printer.
有没有办法做以下事情之一:
Is there a way to do one of the following things:
- 跳过对话框
- 将打印按钮映射到我编写的函数并打印报告而不显示对话框:类似于
myButton.Click += new EventHandler(myButton_Click);
我查看了 MSDN,但没有发现任何可以改变默认工具栏的内容.
I checked MSDN but found nothing to alter the default toolbar.
我确实找到了 这个讨论 来自 2006 年,其中一个答案基本上说这是不可能的.我想隐藏工具栏并创建自己的工具栏将是一个解决方案,但它有点矫枉过正.
I did find this discussion from 2006, where an answer basically says that it is not possible. I guess that hiding the toolbar and creating my own would be a solution but it's a bit overkill.
更新:这不是重复的.我知道有一个问题叫做如何在不显示表单的情况下打印 ReportViewer 的报告",其中该人希望能够在显示之间进行选择表格并打印报告.这不是我的问题.我确实想要显示表单,并且我希望当我单击打印"按钮时,它会打印报告,不询问我使用哪台打印机.
UPDATE: This is not a duplicate. I know there is a question called "How to print a ReportViewer's report without showing a form", in which the guy wants to be able to choose between showing the form and printing the report. This is not my problem. I do want to display the form, and I want that when I click on the Print button, it prints the report, without asking me which printer to use.
推荐答案
我找到了解决方案!
更准确地说,我找到了一种使您能够调用自定义打印功能的解决方法.
More precisely I found a workaround that enables you to call a custom printing function.
您需要使用 打印 事件.
然后您可以捕获该事件,取消它并调用您自己的打印函数:
You can then catch the event, cancel it and call your own printing function:
myViewer.Print += new CancelEventHandler(myViewer_Print);
void myViewer_Print(object sender, CancelEventArgs e)
{
e.Cancel = true;
MyCustomPrintFunction();
}
这篇关于更改 ReportViewer C# 中打印按钮的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!