【问题标题】:how to customize ReportViewer printDialog for selected printers only如何仅为选定的打印机自定义 ReportViewer printDialog
【发布时间】:2026-02-11 18:45:01
【问题描述】:

我正在使用下面的代码在窗口窗体上调用我的 SSRS 报告。

 reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote;
                reportViewer1.ServerReport.ReportServerUrl = new Uri(textBox1.Text);
                reportViewer1.ServerReport.ReportPath = textBox2.Text;
                reportViewer1.RefreshReport();

现在报告加载后,在打印对话框中显示所有打印机列表。但客户要求是在选择的打印机列表中只显示几台打印机。

我如何使用 c# 来做到这一点?

【问题讨论】:

  • 您可以通过ReportViewer 对象上的ReportViewer.PrinterSettings 属性设置默认打印机设置。然后这些用于初始化打印对话框;不确定您是否可以继续限制显示的打印机。删除和/或隐藏它们是否意味着它们肯定会被卸载?
  • 它不起作用,我已经尝试过了,

标签: c# reporting-services window ssrs-2008


【解决方案1】:
 public static ArrayList GetPrinters()
    {
        ArrayList ArrayPrinters = new ArrayList();

        PrintDocument prtdoc = new PrintDocument();
        //prt.PrinterSettings.PrinterName returns the name of the Default Printer
        string strDefaultPrinter = prtdoc.PrinterSettings.PrinterName;

        //this will loop through all the Installed printers and add the Printer Names to a ComboBox.
        foreach (String strPrinter in PrinterSettings.InstalledPrinters)
        {
            //This will insert the Default Printer Name matches with the current Printer Name returned by for loop
            if (strPrinter.CompareTo(strDefaultPrinter) == 0)
            {
                ArrayPrinters.Insert(0, strPrinter);
            }
            else
            {
                ArrayPrinters.Add(strPrinter);
            }
        }
        return ArrayPrinters;
    }

【讨论】:

  • 或者使用Combobox填充Papersize,Orientation,PaperSize PrintSettings.SetPaperSize(document, cmbPaperSize1.Text, PaperOrientation.Portrait, cmbPrinter.Text);
  • 不,我只想在列表中显示有限的打印机名称。我不想更改其他设置。
最近更新 更多