# ServerTextControl and MailMerge Classes in Windows Forms

> With the X9 Professional license, ServerTextControl and MailMerge classes are available in Windows Forms applications. ServerTextControl handles background document processing without a GUI, while MailMerge connects to a visible TextControl for template-based data merging.

- **Author:** Bjoern Meyer
- **Published:** 2013-07-29
- **Modified:** 2026-03-05
- **Description:** With the X9 Professional license, ServerTextControl and MailMerge classes are available in Windows Forms applications. ServerTextControl handles background document processing without a GUI, while MailMerge connects to a visible TextControl for template-based data merging.
- **4 min read** (783 words)
- **Tags:**
  - Tutorial
- **Web URL:** https://www.textcontrol.com/blog/2013/07/29/servertextcontrol-and-mailmerge-classes-in-windows-forms/
- **LLMs URL:** https://www.textcontrol.com/blog/2013/07/29/servertextcontrol-and-mailmerge-classes-in-windows-forms/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2013/07/29/servertextcontrol-and-mailmerge-classes-in-windows-forms/llms-full.txt

---

**Did you already know that the ServerTextControl and MailMerge classes can be used in visible Windows Forms applications with the X9 Professional client license?**

This is an additional feature we added to the client versions without optional server and run-time licences.

ServerTextControl can be used for all processes in the background where no GUI is required. If you need to prepare a document programmatically before it is displayed to the end-user, you can use an instance of *TXTextControl.ServerTextControl* to create the document with the same API just like with the Windows Forms control *TXTextControl.TextControl*.

Advantages of using ServerTextControl:

1. Better performance
2. Must not be visible on a form
3. No visual update

In order to use the ServerTextControl, you'll need to add a reference to the TXTextControl.Server.dll and an entry in the licenses.licx file:

```
TXTextControl.ServerTextControl, TXTextControl.Server, Culture=neutral, PublicKeyToken=6b83fe9a75cfb638
```

The following code shows how to create an instance of ServerTextControl. An using statement is recommended as the object must be disposed explicitly.

```
using (TXTextControl.ServerTextControl serverTextControl1 
       = new TXTextControl.ServerTextControl()) 
{ 
    serverTextControl1.Create(); 
    ... 
}
```

Using MailMerge in Windows Forms Applications
---------------------------------------------

Not only the ServerTextControl class can be used with the client license in Windows Forms or WPF applications. The MailMerge component can be connected to a visible *TextControl* as well.

The following tutorial shows how to connect MailMerge with TextControl, to load a template and to merge data.

Open Visual Studio and find the TextControl icon in the toolbox tab *TX Text Control 19.0*. Drag and drop an instance of *TextControl* to the form, click the SmartTag in the upper right corner and choose *Add a Button Bar*, *Add a Status Bar*, *Add a Ruler*, *Add a Vertical Ruler* and finally *Arrange Controls Automatically* to connect all controls.

![Using MailMerge in Windows Forms applications](https://s1-www.textcontrol.com/assets/dist/blog/2013/07/29/a/assets/step1.webp "Using MailMerge in Windows Forms applications")Now, find the MailMerge component in the toolbox and drag and drop an instance onto the form:

![Using MailMerge in Windows Forms applications](https://s1-www.textcontrol.com/assets/dist/blog/2013/07/29/a/assets/mailmerge_1.webp "Using MailMerge in Windows Forms applications")Select the MailMerge component to show the *Properties* and pick the *TextControl* from the drop-down box of the *TextComponent* property.

![Using MailMerge in Windows Forms applications](https://s1-www.textcontrol.com/assets/dist/blog/2013/07/29/a/assets/mailmerge_2.webp "Using MailMerge in Windows Forms applications")In the next step, we will create a simple template using *TX Text Control Words*. Open the *SmartTag* again and choose *"Start TXTextControlWords"*.

Choose *New* from the *File* main menu to start with a blank document.

Open the *Mailings* tab which contains all functionality to add a data source, text fields or repeating blocks. For this tutorial, we won't add a data source, but insert fields with a specific name directly.

Click on the *Insert Merge Field* button to open the *Merge Field Options* dialog:

![Using MailMerge in Windows Forms applications](https://s1-www.textcontrol.com/assets/dist/blog/2013/07/29/a/assets/mailmerge_3.webp "Using MailMerge in Windows Forms applications")Type in the field name *company* and confirm with *OK*. Repeat this step with additional fields named "name" and "firstname". You can add additional text and formatting, so that your resulting template looks like this:

![Using MailMerge in Windows Forms applications](https://s1-www.textcontrol.com/assets/dist/blog/2013/07/29/a/assets/mailmerge_4.webp "Using MailMerge in Windows Forms applications")Save the document as a new DOCX document in the directory of your newly created Visual Studio project.

Switch back to Visual Studio, add a *MenuStrip* to the form and add a menu item called *Merge*. ![Using MailMerge in Windows Forms applications](https://s1-www.textcontrol.com/assets/dist/blog/2013/07/29/a/assets/mailmerge_5.webp "Using MailMerge in Windows Forms applications")

Double click the menu item to open the event handler in order to add the following code:

```
// load template
TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings();
ls.ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord;
textControl1.Load("template.docx",
    TXTextControl.StreamType.WordprocessingML, ls);

// create a dummy data source
DataTable dt = new DataTable();

dt.Columns.Add("company");
dt.Columns.Add("firstname");
dt.Columns.Add("name");

dt.Rows.Add(new object[] { "Facebook", "Mark", "Zuckerberg" });
dt.Rows.Add(new object[] { "Microsoft", "Bill", "Gates" });
dt.Rows.Add(new object[] { "Microsoft", "Steve", "Ballmer" });
dt.Rows.Add(new object[] { "Oracle", "Larry", "Ellison" });

// merge template
mailMerge1.Merge(dt, true);
```

Compile and start the application in order to click the menu item. The merged document is loaded back into the connected TextControl instance automatically and the document should have 4 pages now:

![Using MailMerge in Windows Forms applications](https://s1-www.textcontrol.com/assets/dist/blog/2013/07/29/a/assets/mailmerge_6.webp "Using MailMerge in Windows Forms applications")

---

## 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 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)
- [How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/10/16/how-to-mail-merge-ms-word-docx-documents-in-aspnet-core-csharp/llms.txt)
- [Creating an Angular Document Editor Application with a Node.js WebSocket Server](https://www.textcontrol.com/blog/2023/08/24/creating-an-angular-document-editor-application-with-a-nodejs-websocket-server/llms.txt)
- [Adding SVG Watermarks to Documents](https://www.textcontrol.com/blog/2022/01/28/adding-svg-watermarks-to-documents/llms.txt)
- [Using MailMerge in ASP.NET Core 6 Web Applications](https://www.textcontrol.com/blog/2022/01/27/using-mailmerge-in-aspnet-core-6-web-applications/llms.txt)
- [DocumentViewer for React Prerelease](https://www.textcontrol.com/blog/2020/10/27/document-viewer-for-react-prerelease/llms.txt)
- [New DocumentViewer Signature Tutorial Sample](https://www.textcontrol.com/blog/2020/08/18/new-documentviewer-signature-tutorial-sample/llms.txt)
- [Creating an ASP.NET MVC DocumentViewer Application With Razor](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-mvc-documentviewer-application-with-razor/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 Your First WPF Application](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-wpf-application/llms.txt)
- [Creating a WPF Ribbon Application](https://www.textcontrol.com/blog/2020/01/01/creating-a-wpf-ribbon-application/llms.txt)
- [Integrate Document Editing into any HTML Client using the HTML Widget](https://www.textcontrol.com/blog/2020/01/01/integrate-document-editing/llms.txt)
- [Creating an ASP.NET MVC Application With Razor](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-mvc-application-with-razor/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)
- [Creating an ASP.NET Web Forms AJAX Application](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-web-forms-ajax-application/llms.txt)
- [Creating a WebSocket Server Project with Node.js](https://www.textcontrol.com/blog/2020/01/01/creating-a-websocket-server-project-with-nodejs/llms.txt)
- [Creating an Angular Document Editor Application](https://www.textcontrol.com/blog/2020/01/01/creating-an-angular-document-editor-application/llms.txt)
- [ReportingCloud .NET Core Quickstart Tutorial](https://www.textcontrol.com/blog/2019/07/24/reportingcloud-dotnet-core-quickstart-tutorial/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)
- [Create your First Document with ReportingCloud](https://www.textcontrol.com/blog/2019/02/19/create-your-first-document-with-reportingcloud/llms.txt)
- [MailMerge: Starting Each Merge Block on a New Page](https://www.textcontrol.com/blog/2016/09/09/mailmerge-starting-each-merge-block-on-a-new-page/llms.txt)
- [Windows Forms and WPF: End a List on Return when Line is Empty](https://www.textcontrol.com/blog/2016/08/26/windows-forms-and-wpf-end-a-list-on-return-when-line-is-empty/llms.txt)
- [Using IFormattedText Objects to Access Elements Across All TextParts in a Document](https://www.textcontrol.com/blog/2016/08/25/using-iformattedtext-objects-to-access-elements-across-all-textparts-in-a-document/llms.txt)
