0

在以下代码段中,我获取默认打印机设置,并使用从已从 InstalledPrinters 属性填充的组合框中选择的打印机名称覆盖 PrinterName。

然后我将副本数设置为一个小的整数值。

public void Print(){
        CurrentPageIndex = 0;
        PrintDocument printDoc = new PrintDocument();
        printDoc.DocumentName = "Report";
        printDoc.PrinterSettings = new PrinterSettings();
        printDoc.PrinterSettings.PrinterName = this.PrinterName;
        printDoc.PrinterSettings.Copies = this.Copies;

        if (!printDoc.PrinterSettings.IsValid)
        {
            throw new ArgumentException("PrinterSettings");
        }

        ImageDimensions = new FrameDimension(RenderedImage.FrameDimensionsList[0]);
        FrameCount = RenderedImage.GetFrameCount(ImageDimensions);

        printDoc.PrintPage += new PrintPageEventHandler(PrintPageHandler);

        printDoc.Print();
    }

    private void PrintPageHandler(object sender, PrintPageEventArgs e)
    {
        RenderedImage.SelectActiveFrame(ImageDimensions, CurrentPageIndex);
        e.Graphics.DrawImage(RenderedImage, new Point(0, 0));
        CurrentPageIndex++;
        e.HasMorePages = (CurrentPageIndex < 0);
    }

当我检查行中的打印机设置时if(!printDoc.PrinterSettings.IsValid),我总是认为设置无效。

我认为采用默认设置并更改打印机名称和份数应该会给我有效的 PrinterSettings。

4

0 回答 0