This example shows how to place a watermark on the report page. Watermark on the page can be text, the result of the expression, or an image. Also watermark can be placed anywhere on the page. In this example we will add a text watermark. For this, we use the drawing page event of the report:
static void Main() 
{
	// Enable HiDPI mode
	Stimulsoft.Report.Win.StiDpiAwarenessHelper.SetPerMonitorDpiAware();

	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)
	{
		var page = sender as StiPage;
		DrawCopyright(page, e);
	}
}

private static void OnPagePainted(StiPage sender, StiPagePaintEventArgs e)
{
	if (copyrightPosition == Position.Front)
	{
		var page = sender as StiPage;
		DrawCopyright(page, e);
	}
}

The method of rendering the watermark is below:
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;
	
	var 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);
	}
}

Auf dem Screenshot unten Sie können das Ergebnis des Beispiel-Codes ansehen:

Using the Report Page Canvas for the Copyrights

By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.