将完整的Windows表单发送到打印机.

将完整的Windows表单发送到打印机.

问题描述:

我可以将完整的Windows表单发送给打印机以在屏幕上显示其所有内容(带有文本和图像的控件)吗?如果是,请为其提供代码.

Can I send complete windows form to printer to print with all its contents (controls with text and images) displaying on screen? If yes, please provide code for it.

http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/eb80fbbe-6b89-4c3d-9ede-88a2b105c714 [ ^ ]
不使用API​​打印Windows窗体 [ Google [ ^ ]还有更多.
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/eb80fbbe-6b89-4c3d-9ede-88a2b105c714[^]
Print Windows Forms w/o using API[^]

Google[^] has many more.




Prera​​ks的回答非常好,但是CP文章对可打印控件有一些限制.只是添加一种简单的方法.您可以使用以下代码从任何控件(例如您的表单)创建位图:
Hi,

Preraks answer is very good, but the CP article has some limitations about the controls that can be printed. Just to add one simple way. You can create a bitmap from any control (e.g. your form) by using this code:
Bitmap bmp = new Bitmap(this.Width, this.Height);
this.DrawToBitmap(bmp, Rectangle.FromLTRB(0, 0, this.Width, this.Height));
//bmp.Save("C:\\Test.bmp"); // save it to a file or send it to the printer


创建位图后,您可以使用它进行任何操作-因此将其发送到打印机应该非常容易.
希望对您有所帮助!


After creating the bitmap you can do anything you want with it - so it should be quite easy to send it to the printer.
I hope it helps!