我正在尝试屏幕捕获窗体,提供打印预览然后打印。表单在纸张上打印,但是prin预览显示消息“文档不包含任何页面”/
以下是我的代码中的相关摘要。请让我知道我哪里出错了。
Bitmap bmp; // Variable for Bitmap of actual page to print
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) //Click to Print
{
Graphics g = this.CreateGraphics();
bmp = new Bitmap(this.Size.Width, this.Size.Height, g);
Graphics mg = Graphics.FromImage(bmp);
mg.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, this.Size);
//printPreviewDialog1.ShowDialog();
//printDocument1.Print();
printPreviewDialog1.Document = printDocument1;
// printPreviewDialog1.PrintPreviewControl.Zoom = 1;
printPreviewDialog1.ShowDialog();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(bmp, 0, 0);
}