使用MSDN中有关如何打印Windows窗体的代码示例,我已经改变了我的第一个打印机选项,然后打印,但我一直收到一个空白页面。使用CopyFromScreen
,我给出了表格源X&的坐标。是的,但是对于目的地,我尝试了0
以及this.Location.X & Y
。还有另一种捕获图像的方法吗?
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);
}