TX Text Control .NET for Windows Forms Documentation

Step 5: Text Formatting

This sample shows how to use the Selection class to create a Selection object, add text and the formatting and how to insert it into the current document. It shows just 4 simple formattings: bold, italic, underline and strikeout.

The ASP.NET web form contains a CheckBox list where the user is able to select the formatting. The web form can be seen on the screenshot below:

After pressing the button, a selection object is created and the text is inserted and formatted according to the selected values. The following code snippet creates the Selection object and adds the text and the formatting.

[C#] TXTextControl.Selection formattedSelection = new TXTextControl.Selection(); formattedSelection.Text = TextBox1.Text; foreach(ListItem selectItem in CheckBoxList1.Items) { if(selectItem.Selected == true) { switch(selectItem.Value) { case "bold": formattedSelection.Bold = true; break; case "italic": formattedSelection.Italic = true; break; case "underline": formattedSelection.Underline = TXTextControl.FontUnderlineStyle.Single; break; case "strikeout": formattedSelection.Strikeout = true; break; } } }
[Visual Basic] Dim formattedSelection As New TXTextControl.Selection formattedSelection.Text = TextBox1.Text For Each selectItem As ListItem In CheckBoxList1.Items If selectItem.Selected = True Then Select Case selectItem.Value Case "bold" formattedSelection.Text = TextBox1.Text Case "italic" formattedSelection.Italic = True Case "underline" formattedSelection.Underline = TXTextControl.FontUnderlineStyle.Single Case "strikeout" formattedSelection.Strikeout = True End Select End if Next

Finally, the Selection object will be added to the document:

[Visual Basic] ServerTextControl1.Selection = formattedSelection
[C#] serverTextControl1.Selection = formattedSelection;
 
 
 

Products

Support

Downloads

Corporate

Buy Now