Back to Devexpress

Page.WatermarkId Property

corelibraries-devexpress-dot-xtraprinting-dot-page.md

latest7.4 KB
Original Source

Page.WatermarkId Property

Specifies the unique identifier of a watermark to be displayed on a page.

Namespace : DevExpress.XtraPrinting

Assembly : DevExpress.Printing.v25.2.Core.dll

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
[DefaultValue("")]
public string WatermarkId { get; set; }
vb
<DefaultValue("")>
Public Property WatermarkId As String

Property Value

TypeDefaultDescription
StringString.Empty

A watermark unique identifier.

|

Remarks

When a Document is generated, all its Document.Pages contain a watermark which is specified by the PrintingSystemBase.Watermarks property of a document’s printing system.

To specify individual watermarks for particular pages, use the Page.WatermarkId property or call the Page.AssignWatermark method.

Example

The following example demonstrates how to specify a unique watermark for different pages in a report. You can do it in the following ways:

  • Assign the Page.WatermarkId property to the Watermark.Id value.

  • Call the Page.AssignWatermark method for the page whose watermark you want to change, and pass a new watermark to this method as a parameter.

Page.AssignWatermark takes priority over Page.WatermarkId.

If you want to remove the watermark from a particular page, pass a new empty watermark to the AssignWatermark method.

View Example

cs
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.Drawing;
using DevExpress.XtraPrinting;
using DevExpress.XtraPrinting.Drawing;
using DevExpress.XtraReports.UI;
// ...

namespace DifferentWatermarks {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

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

            // Add a custom watermark to the second page.
            Page myPage = report.Pages[1];
            myPage.WatermarkId = "Watermark2";

            // 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, string id) {
            Watermark textWatermark = new Watermark();
            textWatermark.Id = id;
            textWatermark.Text = text;
            textWatermark.TextDirection = DirectionMode.ForwardDiagonal;
            textWatermark.Font = new DXFont(textWatermark.Font.Name, 40);
            textWatermark.ForeColor = Color.DodgerBlue;
            textWatermark.TextTransparency = 150;
            textWatermark.TextPosition = WatermarkPosition.InFront;
            return textWatermark;
        }

    }
}
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.Drawing
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraPrinting.Drawing
Imports DevExpress.XtraReports.UI
' ...

Namespace DifferentWatermarks
    Partial Public Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
            ' Create a report and assign a watermark to it.
            Dim report As New XtraReport1()
            report.Watermarks.Add(CreateTextWatermark("Common Watermark", "Watermark1"))
            report.Watermarks.Add(CreateTextWatermark("Second Page", "Watermark2"))
            report.CreateDocument()

            ' Add a custom watermark to the second page.
            Dim myPage As Page = report.Pages(1)
            myPage.WatermarkId = "Watermark2"

            ' Remove a watermark from the third page.
            myPage = report.Pages(2)
            myPage.AssignWatermark(New PageWatermark())

            ' Show the Print Preview.
            report.ShowPreviewDialog()
        End Sub

        ' Create a watermark with the specified text.
        Private Function CreateTextWatermark(ByVal text As String, ByVal id As String) As Watermark
            Dim textWatermark As New Watermark()
            textWatermark.Id = id
            textWatermark.Text = text
            textWatermark.TextDirection = DirectionMode.ForwardDiagonal
            textWatermark.Font = New DXFont(textWatermark.Font.Name, 40)
            textWatermark.ForeColor = Color.DodgerBlue
            textWatermark.TextTransparency = 150
            textWatermark.TextPosition = WatermarkPosition.InFront
            Return textWatermark
        End Function

    End Class
End Namespace

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the WatermarkId property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

reporting-winforms-watermark-different-pages/CS/Form1.cs#L25

csharp
Page myPage = report.Pages[1];
myPage.WatermarkId = "Watermark2";

reporting-winforms-watermark-different-pages/VB/Form1.vb#L27

vb
Dim myPage As Page = report.Pages(1)
myPage.WatermarkId = "Watermark2"

See Also

Page Class

Page Members

DevExpress.XtraPrinting Namespace