Styles in TX Text Control

The usage of style sheets is a elegant, abstract way to separate the formatting from the associated text. You might use this feature in MS Word without understanding the word processing background of it. Every time, you are using a template to write a letter or fax in MS Word, styles are used to control the text formatting.

Using styles, the formatting can be stored, modified and applied separately from the text. In HTML, this style information is saved in the CSS format in the HTML header or in a separate file. In other formats such as DOCX or the internal TX Text Control format, styles are stored in separate tables in the document format itself.

Make changes to the formatting once and let the styles do the work for you. Consider the following scenario: You want to change each and every heading in your 100 page document. Instead of applying the new style to every paragraph, you simply change the associated style in order to apply the changes to the document.

Changing a style can be done using the ready-to-use dialog box and using the powerful API of TX Text Control. TX Text Control differentiates between ParagraphStyles and InlineStyles - both derivatives of the base class FormattingStyle.

The following code shows how to create and apply a new style to the paragraph at the current input position:

ParagraphStyle psHeading1 = new ParagraphStyle("Heading 1");
psHeading1.Bold = true;
psHeading1.FontSize = 1000;
psHeading1.Underline = FontUnderlineStyle.Doubled;


textControl1.Selection.FormattingStyle = psHeading1.Name;

In case that the style already exists in the document, you can use the code snippet below to modify and apply an existing style:

ParagraphStyle psStyle = textControl1.ParagraphStyles.GetItem("Heading 1");
psStyle.Italic = true;


In this case, the formatting of all paragraphs with this specific style is changed at once.

Start today and download a fully featured, 30 day trial version