private void btnPrint_Click(object sender, System.EventArgs e)
{
Graphics graphic = panelReports.CreateGraphics();
Size s = panelReports.Size;
Bitmap memImage = new Bitmap(s.Width, s.Height, graphic);
Graphics memGraphic = Graphics.FromImage(memImage);
IntPtr dc1 = graphic.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
BitBlt(dc2, 0, 0, panelReports.ClientRectangle.Width, panelReports.ClientRectangle.Height,
dc1, 0, 0, 13369376);
//Clone the bitmap so we can dispose it.
print_image = (Image)memImage.Clone();
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
graphic.Dispose();
memGraphic.Dispose();
memImage.Dispose();
PrintPreviewDialog dlg = new PrintPreviewDialog() ;
dlg.Width = 800;
dlg.Height = 600;
dlg.Document = printDocument1;
if (dlg.ShowDialog() == DialogResult.OK)
printDocument1.Print();
}
panelReports是panel的name
温馨提示:答案为网友推荐,仅供参考