# Inserting Watermark Images to All Pages Dynamically

> Dynamically insert centered watermark images on every page of a TX Text Control document. The approach tags each watermark using the Image Name property, removes existing watermarks before reinserting them, and monitors the Changed event to add watermarks when new pages are created.

> **Note:** This article is outdated and may no longer be accurate.

- **Author:** Bjoern Meyer
- **Published:** 2015-07-17
- **Modified:** 2026-07-17
- **Description:** Dynamically insert centered watermark images on every page of a TX Text Control document. The approach tags each watermark using the Image Name property, removes existing watermarks before reinserting them, and monitors the Changed event to add watermarks when new pages are created.
- **3 min read** (495 words)
- **Tags:**
  - GitHub
  - Reporting
  - Tutorial
  - Windows Forms
- **Web URL:** https://www.textcontrol.com/blog/2015/07/17/inserting-watermark-images-to-all-pages-dynamically/
- **LLMs URL:** https://www.textcontrol.com/blog/2015/07/17/inserting-watermark-images-to-all-pages-dynamically/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2015/07/17/inserting-watermark-images-to-all-pages-dynamically/llms-full.txt
- **GitHub Repository:** https://github.com/TextControl/TextControl.Watermarks

---

This sample project shows how to create and insert a watermark image on all pages dynamically. *Image* objects have the [Name](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.framebase.name.property.htm) property to store additional string information with an image. This property is used to tag the inserted watermark images in order to find them in the [ImageCollection](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.imagecollection.class.htm).

In a first step, all watermark images are removed. In order to remove the specific images, all tagged images are collected in a *List* and finally removed from the *ImageCollection*:

```
private void RemoveWatermarkImages(TXTextControl.TextControl textControl)
{
    // List of images to be deleted
    List<TXTextControl.Image> lImagesToRemove = 
        new List<TXTextControl.Image>();

    // loop through all images and check for the Name
    foreach (TXTextControl.Image img in textControl1.Images)
    {
        // add watermark images to the List
        if (img.Name == "Watermark")
            lImagesToRemove.Add(img);
    }

    // remove all tagged watermark images
    foreach(TXTextControl.Image img in lImagesToRemove)
    {
        textControl1.Images.Remove(img);
    }
}
```

After that, on each page, a new watermark image is inserted at a fixed position, vertically and horizontally centered. The *Name* property is set to *"Watermark"* and the image won't be sizable and moveable.

```
private void InsertWatermarkImages()
{
    // remove all existing watermarks
    RemoveWatermarkImages(textControl1);

    foreach (TXTextControl.Page page in textControl1.GetPages())
    {
        // create a new watermark image
        Bitmap bmp = CreateDraftImage();

        // create a new TXTextControl.Image object and mark
        // as watermark
        TXTextControl.Image img = new TXTextControl.Image(bmp);
        img.Name = "Watermark";
        img.Sizeable = false;
        img.Moveable = false;

        // calculate the location to center the image
        Point pImageLocation = new Point(
            (page.Bounds.Width / 2) - (PixelToTwips(bmp.Size.Width)) / 2,
            (page.Bounds.Height / 2) - (PixelToTwips(bmp.Size.Height)) / 2);

        // add the image to the page
        textControl1.Images.Add(
            img,
            page.Number,
            pImageLocation,
            TXTextControl.ImageInsertionMode.BelowTheText);
    }
}
```

On the TextControl [Changed](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.textcontrol.changed.event.htm) event, a simple condition checks whether the current number of pages has been increased. If yes, a new watermark is inserted:

```
private int iNumberOfPages = 1;

// update the watermarks if the number of pages are different
private void textControl1_Changed(object sender, EventArgs e)
{
    if (textControl1.Pages > iNumberOfPages)
    {
        InsertWatermarkImages();
        iNumberOfPages = textControl1.Pages;
    }
}
```

To complete the code description: The method *CreateDraftImage* returns a *Bitmap* with the gray text *"DRAFT"* that is used as a watermark image.

```
// creates a new "DRAFT" sample image
private Bitmap CreateDraftImage()
{
    string sText = "DRAFT";

    Bitmap destination = new Bitmap(400, 400);
    using (Graphics g = Graphics.FromImage(destination))
    {
        GraphicsUnit units = GraphicsUnit.Pixel;

        g.Clear(Color.White);
        StringFormat stringFormat = new StringFormat();
        stringFormat.Alignment = StringAlignment.Center;
        stringFormat.LineAlignment = StringAlignment.Center;

        g.DrawString(sText, new Font(
            "Arial", 
            90, 
            FontStyle.Bold,
            GraphicsUnit.Pixel), 
            new SolidBrush(
                Color.FromArgb(64, Color.Black)),
                destination.GetBounds(ref units),
                stringFormat);
    }

    return destination;
}
```

The following screenshot shows the watermarks in the TX Text Control .NET for Windows Forms:

![Inserting watermark images to all pages dynamically](https://s1-www.textcontrol.com/assets/dist/blog/2015/07/17/a/assets/watermark_image.webp "Inserting watermark images to all pages dynamically")Download the sample from GitHub and test it on your own.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Windows Forms: Printing Multiple Pages Per Sheet](https://www.textcontrol.com/blog/2015/07/24/windows-forms-printing-multiple-pages-per-sheet/llms.txt)
- [MailMerge: Conditional INCLUDETEXT Fields](https://www.textcontrol.com/blog/2015/01/08/mailmerge-conditional-includetext-fields/llms.txt)
- [Merging Documents with RESTful Web API's](https://www.textcontrol.com/blog/2015/07/31/merging-documents-with-restful-web-apis/llms.txt)
- [Reporting: Sorting Merge Block Rows by Column Name](https://www.textcontrol.com/blog/2015/07/15/reporting-sorting-merge-block-rows-by-column-name/llms.txt)
- [Reporting: Merging MS Word Documents with DocVariables](https://www.textcontrol.com/blog/2015/06/10/reporting-merging-ms-word-documents-with-docvariables/llms.txt)
- [Windows Forms Tutorial: Create Your First Windows Forms C# Application](https://www.textcontrol.com/blog/2024/08/26/windows-forms-tutorial-create-your-first-windows-forms-csharp-application/llms.txt)
- [TX Text Control 32.0 Has Been Released](https://www.textcontrol.com/blog/2023/09/13/tx-text-control-320-has-been-released/llms.txt)
- [Official TX Text Control .NET Sample Applications Are Now Hosted on GitHub](https://www.textcontrol.com/blog/2023/01/08/official-tx-text-control-net-sample-applications-are-now-hosted-on-github/llms.txt)
- [TX Text Control 31.0 and TX Spell .NET 10.0 Have Been Released](https://www.textcontrol.com/blog/2022/09/07/tx-text-control-31-released/llms.txt)
- [TX Text Control 30.0 and TX Spell .NET 9.0 Have Been Released](https://www.textcontrol.com/blog/2021/11/29/tx-text-control-30-released/llms.txt)
- [TX Text Control X19 and TX Spell 8.0 Have Been Released](https://www.textcontrol.com/blog/2020/12/02/tx-text-control-x19-released/llms.txt)
- [TX Text Control X18 has been Released](https://www.textcontrol.com/blog/2020/03/16/tx-text-control-x18-released/llms.txt)
- [Creating Your First Windows Forms Application with C#](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-windows-forms-application-with-csharp/llms.txt)
- [Creating A Windows Forms Ribbon Application](https://www.textcontrol.com/blog/2020/01/01/creating-a-windows-forms-ribbon-application/llms.txt)
- [Creating Your First ASP.NET Reporting Application](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-aspnet-reporting-application/llms.txt)
- [Merge Excel Documents into MailMerge Templates using IncludeText Fields](https://www.textcontrol.com/blog/2019/08/13/merge-excel-documents-into-mailmerge-templates/llms.txt)
- [Document Permissions and Password Encryption](https://www.textcontrol.com/blog/2019/07/05/document-permissions-and-password-encryption/llms.txt)
- [New Online Sample: Build your First Report](https://www.textcontrol.com/blog/2019/07/03/build-your-first-report/llms.txt)
- [MailMerge: Conditional Table Cell Colors using Filter Instructions](https://www.textcontrol.com/blog/2019/06/06/mailmerge-conditional-table-cell-colors-using-filter-instructions/llms.txt)
- [MailMerge: Using Filters to Remove Unwanted Rows](https://www.textcontrol.com/blog/2019/06/04/mailmerge-using-filters-to-remove-unwanted-rows/llms.txt)
- [TX Text Control X17 has been Released](https://www.textcontrol.com/blog/2019/05/28/tx-text-control-x17-released/llms.txt)
- [Create and Modify Adobe PDF Documents within your .NET Application](https://www.textcontrol.com/blog/2019/05/27/create-and-modify-adobe-pdf-documents/llms.txt)
- [Creating Templates: Typical Invoice Elements](https://www.textcontrol.com/blog/2019/04/16/typical-invoice-elements/llms.txt)
- [Text Control Roadmap 2019: High DPI Support, Forms, Node.js and Angular](https://www.textcontrol.com/blog/2019/03/12/text-control-roadmap-2019/llms.txt)
- [Create your First Document with ReportingCloud](https://www.textcontrol.com/blog/2019/02/19/create-your-first-document-with-reportingcloud/llms.txt)
