第一种方法:
DevExpress.XtraPrinting.DynamicPrintHelper ph = new DevExpress.XtraPrinting.DynamicPrintHelper();
if (ph.IsPrintingAvailable)
{
ph.PageSettings = set_print_page;
ph.PageSettings.Landscape = true;
ph.ShowPreview(this.gc, true);
}
第二种方法:
{
DataRowView drv = (DataRowView)BS_Roads.Current;
PrintingSystem ps = new PrintingSystem();
PrintableComponentLink link = new PrintableComponentLink(ps);
link.Component = gc;
link.Landscape = true;
PageHeaderFooter phf = link.PageHeaderFooter as PageHeaderFooter;
phf.Header.Content.Clear();
phf.Header.Content.AddRange(new string[] { "", drv["线路名"].ToString() + "站点信息表", "" });
phf.Header.Font = new System.Drawing.Font("宋体", 16, System.Drawing.FontStyle.Regular);
phf.Header.LineAlignment = BrickAlignment.Center;
phf.Footer.Content.Clear();
phf.Footer.Content.AddRange(new string[] { "", String.Format("打印时间: {0:g}", DateTime.Now), "" });
link.CreateDocument();
link.ShowPreview();
}
else
{
XtraMessageBox.Show("打印机不可用...", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
#region 水印图片
reportPrint.ShowPrintStatusDialog = false;
#endregion
PrintableComponentLink printLink = new PrintableComponentLink(reportPrint);
reportPrint.Links.Add(printLink);
printLink.Component = sheet;//这里可以是可打印的部件
#region 报表的页眉页脚的设置
PageHeaderFooter phf = printLink.PageHeaderFooter as PageHeaderFooter;
phf.Header.Content.Clear();
phf.Header.Content.AddRange(new string[] { "", printHeader, "" });
phf.Header.Font = new System.Drawing.Font("微软雅黑", 14, System.Drawing.FontStyle.Bold);
phf.Header.LineAlignment = BrickAlignment.Center;
phf.Footer.Content.Clear();
phf.Footer.Content.AddRange(new string[] { "", "", "第[页#]页 共 [页 #]页" });
#endregion