Loading Markdown Content into TX Text Control
Markdown is a lightweight markup language that implements a plain-text-formatting syntax for easy-to-use formatting. This sample shows how to load Markdown into TX Text Control.

What is Markdown?
Markdown is a popular way to create content on the web. It is a very simple set of formatting rules to format words as bold or italic, adding images and to create lists. Many developers use Markdown for documentation files for repositories like in GitHub, Gists and readme files.
The popular NuGet package Markdig is able to parse Markdown content in order to create clean HTML. The project is also hosted on GitHub:
In this sample, we utilize this package to convert the plain text Markdown content of a Text
Thanks to the clean output of the Markdown parser, it is very easy to style the various stylesheet elements within TX Text Control. This way, you can create pixel-perfect documents such as Adobe PDF from your Markdown content.
LoadMarkdown Extension Method
The sample implements the extension method LoadMarkdown for TX Text Control to load Markdown directly:
textControl2.LoadMarkdown(textControl1.Text);
The implementation of this method is shown below:
public static class TextControlExtensions
{
public static void LoadMarkdown(this TXTextControl.TextControl textControl,
string markdown)
{
textControl.Load(ParseMarkdown(markdown), TXTextControl.StringStreamType.HTMLFormat);
}
private static string ParseMarkdown(string markdownInput)
{
var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
return Markdown.ToHtml(markdownInput, pipeline);
}
}
You can download the Windows Forms sample from our GitHub repository below. This concept is not limited to Windows Forms, but can be used with all TX Text Control versions.
Also See
This post references the following in the documentation:
- TXText
Control. Text Control. Load Method
Download and Fork This Sample on GitHub
We proudly host our sample code on github.com/TextControl.
Please fork and contribute.
Requirements for this sample
- Visual Studio 2019
- TX Text Control .NET for Windows Forms X18 (trial sufficient)
Windows Forms
Text Control combines the power of a reporting tool and an easy-to-use WYSIWYG word processor - fully programmable and embeddable in your Windows Forms application. TX Text Control .NET for Windows Forms is a royalty-free, fully programmable rich edit control that offers developers a broad range of word processing features in a reusable component for Visual Studio.
Related Post
Converting Markdown to DOCX and PDF in C#
Markdown is a popular, lightweight markup language to create formatted text in a simple way. This article shows how to convert Markdown files to Office Open XML and PDF documents using TX Text…