求助 C#打印picturebox
我导入数据后,picturebox内自动生成了曲线图,我另加了一个打印按钮,希望按下打印按钮后,能够打印picturebox内的曲线图,我是一个初学者,希望高手帮帮忙,先谢谢了!
/// <summary> /// 打印 /// </summary> /// <param name="title">标题</param> /// <param name="printPageEventHandler"></param> public static void Print(string title, PrintPageEventHandler printPageEventHandler) { PrintDocument printDocument1 = new PrintDocument(); PageSetupDialog pageSetupDialog1 = new PageSetupDialog(); PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog(); PrintDialog printDialog1 = new PrintDialog(); printDocument1.PrintPage += printPageEventHandler; printDocument1.DocumentName = title; pageSetupDialog1.PageSettings = new PageSettings(); if (pageSetupDialog1.ShowDialog() == DialogResult.OK) { printDocument1.DefaultPageSettings = pageSetupDialog1.PageSettings; //打印前设置打印机 printDialog1.PrinterSettings = new PrinterSettings(); printDialog1.Document = printDocument1; printPreviewDialog1.Document = printDocument1; // 预览 printPreviewDialog1.ShowDialog(); if (printDialog1.ShowDialog() == DialogResult.OK) { printDocument1.Print(); } } } // 调用 Print("打印曲线图", (sender, e) => { e.Graphics.DrawImage(pictureBox1.Image, 0, 0); });