C#PrinterSettings无效

时间:2012-10-31 09:38:02

标签: c# printing

在下面的代码段中,我获取默认的打印机设置,并使用从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。

0 个答案:

没有答案