文档彩票走势图>>Stimulsoft Reports.WinForms教程-2019>>【Stimulsoft Reports.WinForms教程】使用报表页面画布获取版权
【Stimulsoft Reports.WinForms教程】使用报表页面画布获取版权
【下载Stimulsoft Reports.Ultimate最新版本】
此示例显示如何在报表页面上放置水印,页面上的水印可以是文本,表达的结果或图像。水印也可以放在页面的任何位置。在此示例中,我们将添加文本水印。为此,我们使用报表的绘图页面事件:
static void Main() { StiPage.PagePainting += new StiPagePaintEventHandler(OnPagePainting); StiPage.PagePainted += new StiPagePaintEventHandler(OnPagePainted); Application.EnableVisualStyles(); Application.Run(new Form1()); } private static void OnPagePainting(StiPage sender, StiPagePaintEventArgs e) { if (copyrightPosition == Position.Behind) { StiPage page = sender as StiPage; DrawCopyright(page, e); } } private static void OnPagePainted(StiPage sender, StiPagePaintEventArgs e) { if (copyrightPosition == Position.Front) { StiPage page = sender as StiPage; DrawCopyright(page, e); } }
渲染水印的方法如下:
private static void DrawCopyright(StiPage page, StiPagePaintEventArgs e) { if (e.IsPrinting && (!printer))return; if (e.IsDesigning && (!designer))return; if ((!e.IsDesigning) && (!e.IsPrinting) && (!preview))return; Rectangle rect = e.FullRectangle; if (rectClient)rect = e.ClientRectangle; using (Font font = new Font("Arial", 20 * (float)page.Zoom)) using (StringFormat sf = new StringFormat()) { switch (copyrightPlace) { case Place.TopLeft: sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Near; break; case Place.TopRight: sf.Alignment = StringAlignment.Far; sf.LineAlignment = StringAlignment.Near; break; case Place.Center: sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; break; case Place.BottomLeft: sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Far; break; case Place.BottomRight: sf.Alignment = StringAlignment.Far; sf.LineAlignment = StringAlignment.Far; break; } e.Graphics.DrawString(copyrightString, font, Brushes.Red, rect, sf); } }
示例代码的结果如下图所示: