Page.AssignWatermark(PageWatermark) Method

Assigns a new watermark to a page's Page.Watermark property.

Namespace: DevExpress.XtraPrinting

Assembly: DevExpress.Printing.v20.1.Core.dll

Declaration

public void AssignWatermark(
    PageWatermark source
)
Public Sub AssignWatermark(
    source As PageWatermark
)

Parameters

Name Type Description
source PageWatermark

A PageWatermark object which specifies a new watermark for a page.

Remarks

When a Document is generated, all its Document.Pages contain a watermark which is specified by the PrintingSystemBase.Watermark property of a document's printing system. However, you're able to specify a custom watermark for a particular page via the AssignWatermark method.

Examples

The following example demonstrates how to specify a unique watermark for different pages in a report. For this you need to call the Page.AssignWatermark method for the page whose watermark needs to be changed, and pass a new watermark to this method as a parameter, as shown below. If you need to remove a watermark from a particular page, pass a new empty watermark to the AssignWatermark method.

using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraPrinting;
using DevExpress.XtraPrinting.Drawing;
// ...

private void button1_Click(object sender, EventArgs e) {
    // Create a report and assign a watermark to it.
    XtraReport1 report = new XtraReport1();
    report.Watermark.CopyFrom(CreateTextWatermark("Common Watermark"));
    report.CreateDocument();

    // Add a custom watermark to the second page.
    Page myPage = report.Pages[1];
    myPage.AssignWatermark(CreateTextWatermark("Second Page"));

    // Remove a watermark from the third page.
    myPage = report.Pages[2];
    myPage.AssignWatermark(new PageWatermark());

    // Show the Print Preview.
    report.ShowPreviewDialog();
}

// Create a watermark with the specified text.
private Watermark CreateTextWatermark(string text) {
    Watermark textWatermark = new Watermark();

    textWatermark.Text = text;
    textWatermark.TextDirection = DirectionMode.ForwardDiagonal;
    textWatermark.Font = new Font(textWatermark.Font.FontFamily, 40);
    textWatermark.ForeColor = Color.DodgerBlue;
    textWatermark.TextTransparency = 150;
    textWatermark.ShowBehind = false;

    return textWatermark;
}
See Also