文檔首頁>>Stimulsoft Reports.WinForms教程-2019>>【Stimulsoft Reports.WinForms教程】使用報表頁面畫布獲取版權(quán)
【Stimulsoft Reports.WinForms教程】使用報表頁面畫布獲取版權(quán)
【下載Stimulsoft Reports.Ultimate最新版本】
此示例顯示如何在報表頁面上放置水印,頁面上的水印可以是文本,表達(dá)的結(jié)果或圖像。水印也可以放在頁面的任何位置。在此示例中,我們將添加文本水印。為此,我們使用報表的繪圖頁面事件:
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); } }
示例代碼的結(jié)果如下圖所示: