【发布时间】:2020-07-22 05:32:36
【问题描述】:
我正在尝试从 c# Winforms 中的表单生成打印预览。 已经添加了 PrintPreviewDialog 和 PrintDocument 以及一些代码:
using System.Drawing.Printing;
private Bitmap myImage;
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(myImage, 0, 0);
}
private void Button_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
myImage = new Bitmap(this.Size.Width, this.Size.Height, g);
Graphics mg = Graphics.FromImage(myImage);
mg.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, this.Size);
printPreviewDialog1.ShowDialog();
}
单击按钮后,我得到打印预览,并且这个“文档不包含任何页面”。 有人知道为什么会这样吗?我错过了什么吗?
【问题讨论】:
标签: c# winforms print-preview