PDA

Click to See Complete Forum and Search --> : Passing Image to PrintPreviewDialog


fret
Feb 28th, 2006, 02:08 AM
Hi guys,
I have a problem here, I have an image from certain file path. Now what I want to do is to pass that image to the printpreviewdialog in order to show that image and I don't know where to continue with this sample code:


private void button1_Click(object sender, System.EventArgs e)
{
PrintPreviewDialog t = new PrintPreviewDialog();
printDocument1.PrintPage += new PrintPageEventHandler(pr);
t.Document = printDocument1;

t.ShowDialog();

}

private void pr(object sender, PrintPageEventArgs e)
{
// where source image came from
Image i = Image.FromFile("C:\\idBack.jpg");
i.Dispose();
}

It appears to be blank paper, I know there's missing here. :)

jmcilhinney
Feb 28th, 2006, 02:53 AM
The second argument to the PrintPage event handler has a Graphics property. You use this object to draw whatever you want on the printing surface. In your case you would call its DrawImage method. The printing surface is usually the paper in the printer but in the case of a PrintPreviewDialog it is the PrintPreviewControl that it contains.