Back to Devexpress

WatermarkFormat.TextOptions Property

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-watermarkformat.md

latest4.1 KB
Original Source

WatermarkFormat.TextOptions Property

Returns options for the text watermark.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
TextWatermarkOptions TextOptions { get; }
vb
ReadOnly Property TextOptions As TextWatermarkOptions

Property Value

TypeDescription
TextWatermarkOptions

An object that contains text watermark options.

|

Remarks

The TextOptions property allows you to access and modify text settings (font attributes, text color, and layout) for a watermark.

The example below demonstrates how to change text watermark options. The code iterates through all document sections and updates settings for text watermarks in primary headers. The WatermarkFormat.Type property is used to check the watermark type.

csharp
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System.Drawing;
using System.Linq;
// ...

document.LoadDocument(@"Documents\Watermarks.docx");

// Add a text watermark to the document.
document.WatermarkManager.SetText("CONFIDENTIAL");

foreach (Section section in document.Sections)
{
    // Obtain the section's primary header.
    SubDocument headerContent = section.BeginUpdateHeader();
    // Retrieve the header's watermark.
    Shape watermark = headerContent.Shapes.SingleOrDefault(x => x.Type == ShapeType.Watermark);
    // Change text watermark options.
    if (watermark != null && watermark.WatermarkFormat.Type == WatermarkType.Text)
    {
        watermark.WatermarkFormat.TextOptions.Color = Color.SlateGray;
        watermark.WatermarkFormat.TextOptions.FontFamily = "Segoe UI";
        watermark.WatermarkFormat.TextOptions.Layout = WatermarkLayout.Horizontal;
        watermark.WatermarkFormat.TextOptions.Semitransparent = true;
    }
    section.EndUpdateHeader(headerContent);
}
document.SaveDocument(@"Documents\WatermarksUpd.docx", DocumentFormat.Docx);
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Drawing
Imports System.Linq
' ...

document.LoadDocument("Documents\Watermarks.docx")

' Add a text watermark to the document.
document.WatermarkManager.SetText("CONFIDENTIAL")

For Each section As Section In document.Sections
    ' Obtain the section's primary header.
    Dim headerContent As SubDocument = section.BeginUpdateHeader()
    ' Retrieve the header's watermark.
    Dim watermark As Shape = headerContent.Shapes.SingleOrDefault(Function(x) x.Type = ShapeType.Watermark)
    ' Change text watermark options.
    If watermark IsNot Nothing AndAlso watermark.WatermarkFormat.Type = WatermarkType.Text Then
        watermark.WatermarkFormat.TextOptions.Color = Color.SlateGray
        watermark.WatermarkFormat.TextOptions.FontFamily = "Segoe UI"
        watermark.WatermarkFormat.TextOptions.Layout = WatermarkLayout.Horizontal
        watermark.WatermarkFormat.TextOptions.Semitransparent = True
    End If
    section.EndUpdateHeader(headerContent)
Next section
document.SaveDocument("Documents\WatermarksUpd.docx", DocumentFormat.Docx)

The following image demonstrates the result:

See Also

WatermarkFormat Interface

WatermarkFormat Members

DevExpress.XtraRichEdit.API.Native Namespace