B
Bob Morris
I wish to use a PrintPreviewDialog to print documents and at the same time
store images of those docs for audit purposes.
This code saves the images alright, but nothing happens when the print
button in the DialogBox is clicked. If I try getting the
PreviewPrintController reference after the dialog closes (line commented
out) I get an invalid cast exception.
Somewhere the dialog must be setting the document PrintController property
to a PreviewPrintController, but how do I get at it?
Best Regards
//Start here
private void button1_Click(object sender, System.EventArgs e)
{
PrintDocument pdoc = new PrintDocument();
PrintPreviewDialog pdlg = new PrintPreviewDialog();
pdlg.Document = pdoc;
PreviewPrintController ppc = new PreviewPrintController();
pdoc.PrintController = ppc;
pdoc.PrintPage+=new PrintPageEventHandler(pdoc_PrintPage);
// PreviewPrintController ppc =
(PreviewPrintController)pdlg.Document.PrintController;
pdlg.ShowDialog();
PreviewPageInfo[] ppi = ppc.GetPreviewPageInfo();
Image im = ppi[0].Image;
im.Save("PrintImage.bmp");
}
private void pdoc_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
g.DrawString("Hello World",new Font("Arial",12),Brushes.Black,new
PointF(100,100));
}
// to here
store images of those docs for audit purposes.
This code saves the images alright, but nothing happens when the print
button in the DialogBox is clicked. If I try getting the
PreviewPrintController reference after the dialog closes (line commented
out) I get an invalid cast exception.
Somewhere the dialog must be setting the document PrintController property
to a PreviewPrintController, but how do I get at it?
Best Regards
//Start here
private void button1_Click(object sender, System.EventArgs e)
{
PrintDocument pdoc = new PrintDocument();
PrintPreviewDialog pdlg = new PrintPreviewDialog();
pdlg.Document = pdoc;
PreviewPrintController ppc = new PreviewPrintController();
pdoc.PrintController = ppc;
pdoc.PrintPage+=new PrintPageEventHandler(pdoc_PrintPage);
// PreviewPrintController ppc =
(PreviewPrintController)pdlg.Document.PrintController;
pdlg.ShowDialog();
PreviewPageInfo[] ppi = ppc.GetPreviewPageInfo();
Image im = ppi[0].Image;
im.Save("PrintImage.bmp");
}
private void pdoc_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
g.DrawString("Hello World",new Font("Arial",12),Brushes.Black,new
PointF(100,100));
}
// to here