C# 打印窗口

private void cmd_prn_Click(object sender, EventArgs e)
{
if (printDoc.PrinterSettings.IsValid == false) return;
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);

printDoc.Print();
}

 

 printDoc_PrintPage事件添加:

private void printDoc_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}

相关文章