Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Styles Tricks in TX Text Control .NET

This source code snippet requires TX Text Control .NET
Author:TX Text Control Support Department
Language:Visual Basic, Visual Basic .NET
Version:1.0
Released:August 05, 2004
Last modified:January 11, 2008
Requirements:TX Text Control .NET with Visual Studio .NET 2003
Download code:style_selector.zip Download [27.79 KB, ZIP]

Styles Tricks in TX Text Control .NET

Click to enlarge

In this sample, we are going to show you some interesting tricks using styles in TX Text Control .NET

Thanks to the new class oriented design of TX Text Control .NET, manipulating the internal styles of TX Text Control has become very easy. The shipped button bar includes a combo box to select and apply every style to a paragraph. Many customers, however, would like to be able to offer their end-users a style selection box that is not part of the button bar.

We are going to show you how to fill in a combo box with the styles available in TX Text Control. We use a dialog form to create a "style selector" where the user can choose a style and apply it to specific paragraphs.

Using the ParagraphStyleCollection and a simple Visual Basic "For Each" statement, it is very simple to fill a list box with the styles.

  1. Dim style As TXTextControl.FormattingStyle
  2.  
  3. styleDialog.ListBox1.Items.Clear()
  4.  
  5. For Each style In TextControl1.ParagraphStyles
  6. styleDialog.ListBox1.Items.Add(style.Name)
  7. Next

Every available style is displayed in the style selector form and the user can choose one of the styles. In this case, the whole paragraph is selected, so that the selected style can be applied to the complete paragraph. This is done by searching for carriage returns in the text to get to the start and to the end positions of the current paragraph.

  1. paragraphStart = tx.Find(Chr(10), curPos, 17)
  2. paragraphEnd = tx.Find(Chr(10), curPos, 16)

Additionally, the user should be able to see the font settings of the selected style in a preview window. For this reason, we use a second TX Text Control and copy the selected paragraph into the new TX Text Control. The font attributes can be simply applied using the selected style object:

  1. TextControl1.Selection.FontName = tx.ParagraphStyles.GetItem _
  2. (ListBox1.SelectedItem).FontName

Finally, if the user presses the button "Apply", the selected style will be applied to the specified paragraph.

  1. tx.Selection.FormattingStyle = ListBox1.SelectedItem

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place