天天看點

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