0

全部。

我会使用 PrintPreviewControl 来预览带有背景的文档。但我不希望背景被打印出来。

这是我的代码:

    private void button1_Click(object sender, EventArgs e)
    {
        printPreviewDialog1.Document = printDocument1;
        printPreviewDialog1.ShowDialog();
    }

    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        // This background should not print out, but could view in preview
        e.Graphics.DrawImage(new Bitmap(Foobar.Properties.Resources.bg), new Point());
        string text = "This text to be printed. ";
        e.Graphics.DrawString(text, new Font("Georgia", 35, FontStyle.Bold),
            Brushes.Black, 10, 10);            
    }

非常感谢!

4

1 回答 1

0

我解决了这个问题:

    private bool p = true;

    private void button1_Click(object sender, EventArgs e)
    {
        printPreviewDialog1.Document = printDocument1;
        printPreviewDialog1.ShowDialog();
    }

    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        if (!p) {
            e.Graphics.DrawImage(new Bitmap(Foobar.Properties.Resources.bg), new Point());
        }
        string text = "This text to be printed. ";
        e.Graphics.DrawString(text, new Font("Georgia", 35, FontStyle.Bold),
            Brushes.Black, 10, 10);            
    }

    private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
    {
        if (e.PrintAction == System.Drawing.Printing.PrintAction.PrintToPreview) {
            p = false;
        }
    }

    private void printDocument1_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
    {
        p = true;
    }
于 2012-09-19T14:01:48.327 回答