本文介绍了更改打印对话框中显示的份数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Visual Studio 2005的Crystal Reports。我需要更改默认打印机,并将副本数设置为2,而不是默认值1。
I am working on Crystal Reports for Visual Studio 2005. I need to change the default printer, and the number of copies to 2 as compared to the default of 1.
我成功使用以下代码更改了默认打印机。
I have succeeded to change the default printer using below code.
static int SetAsDefaultPrinter(string printerDevice)
{
int ret = 0;
try
{
string path = "win32_printer.DeviceId='" + printerDevice + "'";
using (ManagementObject printer = new ManagementObject(path))
{
ManagementBaseObject outParams =
printer.InvokeMethod("SetDefaultPrinter",
null, null);
ret = (int)(uint)outParams.Properties["ReturnValue"].Value;
}
}
}
如何更改数字
推荐答案
。NetFramework没有提供任何机制来覆盖默认打印功能。因此,我禁用了默认的打印按钮,并在事件处理程序中添加了按钮名称Print.Code,如下所示。
.Net Framework doesn't provide any mechanism to override the default print functionality. So I disabled the default print button, and added a button name Print.Code for the Event Handler follows below.
private void Print_Click(object sender, EventArgs e)
{
try
{
PrintDialog printDialog1 = new PrintDialog();
PrintDocument pd = new PrintDocument();
printDialog1.Document = pd;
printDialog1.ShowNetwork = true;
printDialog1.AllowSomePages = true;
printDialog1.AllowSelection = false;
printDialog1.AllowCurrentPage = false;
printDialog1.PrinterSettings.Copies = (short)this.CopiesToPrint;
printDialog1.PrinterSettings.PrinterName = this.PrinterToPrint;
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
PrintReport(pd);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void PrintReport(PrintDocument pd)
{
ReportDocument rDoc=(ReportDocument)crvReport.ReportSource;
// This line helps, in case user selects a different printer
// other than the default selected.
rDoc.PrintOptions.PrinterName = pd.PrinterSettings.PrinterName;
// In place of Frompage and ToPage put 0,0 to print all pages,
// however in that case user wont be able to choose selection.
rDoc.PrintToPrinter(pd.PrinterSettings.Copies, false, pd.PrinterSettings.FromPage,
pd.PrinterSettings.ToPage);
}
这篇关于更改打印对话框中显示的份数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!