我有一个在我的机器上正确打印的表单但是当我在另一台机器上部署该应用程序时,该表单不适合页面,并且桌面背景出现在打印文档上.两台机器之间的主要区别在于其中一台DPI设置为150%.我已多次更改自动缩放但没有任何变化.表单在屏幕上看起来不错,但是打印不正确.以下是我正在使用的代码.
private void btnPrint_Click(object sender, EventArgs e)
{
CaptureScreen();
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
Bitmap memoryImage;
private void CaptureScreen()
{
Graphics myGraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
}
private void printDocument1_PrintPage(System.Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
Run Code Online (Sandbox Code Playgroud)