DevExpress Dashboard如何实现打印和输出
作者:mayz 来源:本站原创 浏览:Loading...次 发布时间:2013-09-13 评论:0条
下面这段示例演示了如何通过Print Preview打印和输出仪表盘。
使用Show Preview 和 Show Paged Preview两种模式可调用打印预览。Show Preview模式下的纸张尺寸刚好适应仪表盘,但第二个仪表盘要划分到适当数量的标准A4纸中。
首先创建一个DashboardExporter类实现DevExpress.XtraPrinting.IPrintable界面。DashboardExporter实例被映射到一个DashboardViewer,当创建实例之后然后传递到Print Preview,从而使仪表盘能打印到合适的纸上。
参考下面的代码:
using System; using System.Drawing; using System.Windows.Forms; using DevExpress.XtraDashboard; using DevExpress.XtraPrinting; using DevExpress.XtraReports.Native; using DevExpress.XtraReports.UI; namespace DashboardExport { class DashboardExporter : IPrintable { PrintingSystem ps = new PrintingSystem(); PrintableComponentLink componentLink = new PrintableComponentLink(); DashboardViewer viewer; bool paged; public DashboardExporter(DashboardViewer viewer) { this.viewer = viewer; ps.Links.AddRange(new object[] { componentLink }); ps.AfterChange += ps_AfterChange; componentLink.Component = this; } internal void ShowPrintPreview(bool fitPage) { if(fitPage) { componentLink.PaperKind = System.Drawing.Printing.PaperKind.Custom; componentLink.CustomPaperSize = new Size(Convert.ToInt32(Math.Ceiling(viewer.Width / 0.96f)) + 45, Convert.ToInt32(Math.Ceiling(viewer.Height / 0.96f)) + 45); ps.PreviewFormEx.Size = new Size(viewer.Width + 100, viewer.Height + 100); } else { componentLink.PaperKind = System.Drawing.Printing.PaperKind.A4; ps.PreviewFormEx.Size = new Size(0x2f0, 0x274); } componentLink.Margins = new System.Drawing.Printing.Margins(20, 20, 20, 20); componentLink.MinMargins = new System.Drawing.Printing.Margins(0, 0, 0, 0); ps.PreviewFormEx.StartPosition = FormStartPosition.CenterScreen; this.paged = !fitPage; componentLink.CreateDocument(); componentLink.ShowPreview(); } void ps_AfterChange(object sender, ChangeEventArgs e) { switch(e.EventName) { case SR.PageSettingsChanged: case SR.AfterMarginsChange: componentLink.CreateDocument(); break; } } int ToDocument(int value) { return Convert.ToInt32(GraphicsUnitConverter.PixelToDoc(value)); } #region IPrintable void IPrintable.AcceptChanges() { } bool IPrintable.CreatesIntersectedBricks { get { return false; } } bool IPrintable.HasPropertyEditor() { return false; } UserControl IPrintable.PropertyEditorControl { get { return null; } } void IPrintable.RejectChanges() { } void IPrintable.ShowHelp() { } bool IPrintable.SupportsHelp() { return false; } void IBasePrintable.CreateArea(string areaName, IBrickGraphics graph) { if(areaName != "Detail") return; int width; int height; if(paged) { width = viewer.Width; height = viewer.Height; } else { width = Convert.ToInt32(ps.PageSettings.UsablePageSizeInPixels.Width); height = Convert.ToInt32(ps.PageSettings.UsablePageSizeInPixels.Height); } Image bitmap = XRControlPaint.GetControlImage( viewer, WinControlDrawMethod_Utils.UseWMPrintRecursive, WinControlImageType_Utils.Bitmap); graph.DrawBrick(new ImageBrick() { Image = bitmap, SizeMode = ImageSizeMode.CenterImage }, new Rectangle(0, 0, width, height)); } void IBasePrintable.Finalize(IPrintingSystem ps, ILink link) { } void IBasePrintable.Initialize(IPrintingSystem ps, ILink link) { } #endregion } }
本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [http://www.devexpresscn.com/]
本文地址:http://www.devexpresscn.com/Resources/CodeExamples-393.html
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [http://www.devexpresscn.com/]
本文地址:http://www.devexpresscn.com/Resources/CodeExamples-393.html
关键字: DevExpress Dashboard
评论列表
暂无评论
请谈谈你的看法 请使用IE或者Firefox浏览器,暂不支持Chrome!
慧都控件网为DevExpress界面控件的中国地区唯一正式授权经销商,正版控件销售公司,授权代理商,经销商及合作伙伴。
电话:400-700-1020
023-66090381
邮箱:sales@evget.com
相关资源
- 触发barManager里的barItem点击事件
- DevExpress DXCharts应用教程三:创建2D气泡图
- DevExpress DXCharts应用教程四:创建2D烛台图表
- DevExpress DXCharts应用教程五:2D全堆叠图表
- DXCharts应用教程六:2D重叠范围条形图
- XtraCharts网格数据更改时如何刷新图表
- DevExpress DXCharts应用教程七:创建2D点图
- 2012年度DXperience WinForms Subscription中文视频汇总
- DevExpress DXCharts应用教程八:绘制3D面积图
- DevExpress DXCharts应用教程九:绘制3D气泡图
- DevExpress DXCharts应用教程十:绘制3D柱状图
- 如何为eXpressApp Framework设置默认属性值
- DevExpress VCL 12.2.6发布
- DevExpress 12.2.9发布[附下载]
- DevExpress VCL 13.1更新说明[附下载]
- DevExtreme常用示例二:如何在Visual Studio中创建本地封装包
- 如何在DevExtreme中添加phonegap InAppBrowser
- DevExpress 13.1.6更新说明
- 如何创建简单的Windows 8磁贴效果
- DevExpress VCL 13.1.3发布