天天看点

C# 打印整个窗体(不包括边栏)

今天跟人讨论如何打印整个窗体,最原始的思路是:

New bitmap ;

this.DrawBitmap(bitmap,*);

用printDoucument控件中 onprint 事件的 e.Graphics.DrawImage(bitmap,*,*,*,*);

此方法可以实现,但不够完美。经过查资料发现 c# 可调用vb.net中的Visual Basic Power Pack 中的printer控件来实现,且方法简单优雅。

printForm.PrintAction = System.**.PrintToPrinter;

printForm.Print(this,Microsoft.**.ClientAreaOnlu);   //ClientAreaOnly表示只打印窗体,不包括边栏

this.Refresh();

另外这个小工具包中还有几个比较有用的控件,大家可以试试看!

假如装VS时安装了VB.NET,则Visual Basic .NET Power Pack 可在c#工具中看到,若没有,也可自己安装。

本文转自 huohe2009 51CTO博客,原文链接:http://blog.51cto.com/zhaojie/990921