本文介绍了在Winforms C#中打印表单面板时打印空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
printing blank page in printer as well as microsoft xps document also.i changed in below my code.But I am getting blank only.
我尝试过的事情:
What I have tried:
printing blank page in printer as well as microsoft xps document also
private void printButton_Click(object sender, EventArgs e)
{
CaptureScreen();
printDialog1.AllowSomePages = true;
printDialog1.ShowHelp = true;
printDialog1.Document = printDoc1;
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
printDoc1.Print();
}
}
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);
}
void printDoc1_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
推荐答案
memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
memoryImage.Save(@"D:\Temp\Created.jpg", ImageFormat.Jpeg); // ADD THIS
和
e.Graphics.DrawImage(memoryImage, 0, 0);
memoryImage.Save(@"D:\Temp\Printed.jpg", ImageFormat.Jpeg);
然后使用Windows资源管理器查看两个图像.他们是一样的吗?他们是你的物体的照片吗?他们是什么尺寸?还是空白?他们俩都在那里吗?
如果效果很好,则可以开始查看可能导致空白页"的原因-但要确保所绘制的内容是真实的".
Then look at the two images using Windows Explorer. Are they the same? Are they a picture of your object? What size are they? Or are they blank? Are they both even there?
If they are good, then you can start looking at what might be causing the "blank page" - but start be ensuring that what you are drawing is "real".
这篇关于在Winforms C#中打印表单面板时打印空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!