I have a form that prints correctly on my machine but when I deploy the application on another machine, the form does not fit on the page and the desktop background appears on the printed document. The primary differences between the two machines is that one has the DPI setting at 150%. I have changed auto scaling many times but nothing changes. The form looks ok on screen but just does not print correctly. Below is the code I am using.
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);
}