When I click on the print button, the program saves an image to a certain file name. The program then gets the file and print it. But when I do it a second time, the file is in use by another process, even though the printing is done. Is there any way that I can close the file before the print button is pressed again?
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
string pathImage = Environment.CurrentDirectory + "\\chart1.png";
chart1.SaveImage(pathImage, System.Windows.Forms.DataVisualization.Charting.ChartImageFormat.Png);
Image newImage = Image.FromFile(pathImage);
Point ulCorner = new Point(50, 425);
e.Graphics.DrawImage(newImage, ulCorner);
}
private void button4_Click(object sender, EventArgs e)
{
if (printPreviewDialog1.ShowDialog() == DialogResult.OK)
{
printDocument1.Print();
}
}