原創(chuàng)|其它|編輯:郝浩|2013-01-22 15:37:10.000|閱讀 1547 次
概述:DXperience WinForms的ShowPrintPreview等方法提供基本的打印/輸出功能,但這些方法不能自定義打印和輸出時的紙張格式和方向,也不能添加自定義信息到報表中,直接通過XtraPrinting庫就可以打破這些限制。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
DXperience WinForms Subscription 的ExportTo....,Print和ShowPrintPreview 方法提供基本的打印/輸出功能。這些方法不能自定義紙張格式和方向,也不能添加自定義信息到報表中。其實,直接通過XtraPrinting庫就可以打破這些限制。
用XtraPrinting,你可以:
這個方法也適用于DXperience WinForms下所有的控件:XtraGrid, XtraPivotGrid, XtraScheduler, XtraTreeList, XtraCharts, XtraLayoutControl, XtraVerticalGrid 和 XtraGauges。
設置并自定義DXperience WinForms打印/輸出選項的操作步驟如下:
1、添加一個 PrintingSystem組件到表單中
2、添加PrintableComponentLink到PrintingSystem.Links集合中
3、將 PrintableComponentLinkBase.Component屬性部署到控件的打印/輸出
4、如果要自定義紙張,設置鏈接的 LinkBase.PaperKind, LinkBase.Margins和 LinkBase.Landscape屬性為相應的值。
5、如果要為報表添加自定義信息,處理鏈接相應的事件即可。比如, LinkBase.CreateReportHeaderArea事件可以創(chuàng)建報表標題
6、調用鏈接的 Link.CreateDocument 方法
7、打印報表,調用鏈接的 Link.Print 方法
8、顯示報表預覽,調用鏈接的 Link.ShowPreview方法
9、要將報表輸出為指定格式,調用 PrintingSystem組件相應的ExportTo... 方法即可。
示例代碼如下:
using System.Drawing; using DevExpress.XtraPrinting; // Create a PrintingSystem component. PrintingSystem ps = new PrintingSystem(); // Create a link that will print a control. PrintableComponentLink link = new PrintableComponentLink(ps); // Specify the control to be printed. link.Component = customersGridControl; // Set the paper format. link.PaperKind = System.Drawing.Printing.PaperKind.A4; // Subscribe to the CreateReportHeaderArea event used to generate the report header. link.CreateReportHeaderArea += new CreateAreaEventHandler(printableComponentLink1_CreateReportHeaderArea); // Generate the report. link.CreateDocument(); // Show the report. link.ShowPreview(); // Remove the comments below to export the report to a PDF file // link.PrintingSystem.ExportToPdf(@"c:\gridcontrol.pdf"); //... private void printableComponentLink1_CreateReportHeaderArea(object sender, CreateAreaEventArgs e) { string reportHeader = "Customers Report"; e.Graph.StringFormat = new BrickStringFormat(StringAlignment.Center); e.Graph.Font = new Font("Tahoma", 14, FontStyle.Bold); RectangleF rec = new RectangleF(0, 0, e.Graph.ClientPageSize.Width, 50); e.Graph.DrawString(reportHeader, Color.Black, rec, BorderSide.None); }
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件