DevExpress Winform 通用控件打印方法(允许可自定义边距)
2021-06-07 05:02
标签:nts tree syn string center wing syntax pap tco DevExpress Winform 通用控件打印方法,包括gridcontrol,treelist,pivotGridControl,ChartControl,LayoutControl...(所有支持打印功能的控件) ,同时允许用户自定义报表标题,报表纸张类型(A4,A3...),报表边距 DevExpress Winform 通用控件打印方法(允许可自定义边距) 标签:nts tree syn string center wing syntax pap tco 原文地址:https://www.cnblogs.com/xiaoxihebei/p/10755427.html///
/// 打印功能
///
/// 打印控件
/// 标题
/// 纸张类型
/// 边距
protected
virtual
void
Print(IPrintable panel,
string
title =
null
, PaperKind pageSize = PaperKind.A4, System.Drawing.Printing.Margins margins =
null
)
{
PrintingSystem ps =
new
PrintingSystem();
CompositeLink link =
new
CompositeLink(ps); PrintableComponentLink printableLink =
new
PrintableComponentLink() { Component = panel };
ps.Links.Add(link);
link.Links.Add(printableLink);
link.Landscape =
true
;
//横向
link.PaperKind = pageSize;
//设置纸张大小
if
(margins ==
null
)
margins =
new
System.Drawing.Printing.Margins(10, 10, 50, 50);
link.Margins = margins;
//判断是否有标题,有则设置
if
(!
string
.IsNullOrEmpty(title))
{
PageHeaderFooter phf = link.PageHeaderFooter
as
PageHeaderFooter;
phf.Header.Content.Clear();
phf.Header.Content.AddRange(
new
string
[] {
""
, title,
""
});
phf.Header.Font =
new
System.Drawing.Font(
"宋体"
, 14, System.Drawing.FontStyle.Bold);
phf.Header.LineAlignment = BrickAlignment.Center;
phf.Footer.Content.AddRange(
new
string
[] {
""
, String.Format(
"打印时间: {0:g}"
, DateTime.Now),
""
});
}
link.CreateDocument();
//建立文档
ps.PreviewRibbonFormEx.Show();
//进行预览
}
文章标题:DevExpress Winform 通用控件打印方法(允许可自定义边距)
文章链接:http://soscw.com/essay/91592.html