2012-09-19 53 views
0

全部。用bg打印预览控件但不打印出来

我将使用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);    
    } 

非常感谢!

回答

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; 
    }