C#實現PrintPage方法
有的與打印有關的事件和C#實現PrintPage方法
個類包括以下幾個屬性、事件和C#實現PrintPage方法
1、PrinterSettings 屬性
存放打印機的設置信息這個屬性不需要程序員設置因為它是由打印對話框獲取的
2、PrintCountroller 屬性
控制打印過程
3、DefaultPageSettings 屬性
存放頁面設置信息 打印紙大小方向等也不需要程序員設置因為它是由頁面設置對話框獲取的
4、DocumentName 屬性
指定文檔名稱,出現在打印機狀態(tài)窗口中
1、BeginPrint事件,在打印之前發(fā)出
2、PrintPage事件,每打印一頁是發(fā)出,事件接受一個PrintPageEventArgs參數該參數封裝了打印相關的信息
PrintPageEventArgs參數有很多重要的屬性
1 Cancel 取消打印
2 Graphics 頁面的繪圖對象
3 HasMorePages 是否還有要打印的頁面
Print 方法 該方法沒有參數 調用它將按照當前設置開始打印,若實現打印功能首先構造PrintDocument對象添加打印事件。
- PrintDocument printDocument;
- private void InitializeComponent()
- {
- ...
- printDocument=new PrintDocument();
- printDocument.PrintPage += new PrintPageEventHandler (this.printDocument_PrintPage);
- ...
- }
在應用程序窗體初始化時構造PrintDocument對象,添加printDocument的PrintPage方法
C#實現PrintPage方法
在用戶的單擊事件中調用 printDocument 的 Print方法實現打印功能在這中間可能要用到 PrintDialog PrintPreviewDialog PageSetupDialog 設置和查看打印效果這些方法通常是由菜單的單擊觸發(fā)的。
【編輯推薦】