FontItalic on CTRL+i with TX Text Control ActiveX
TX Text Control inserts a tab character when the key combination CTRL+i is used. This short code sample shows you how to trap these keystrokes in order to implement some other behavior, such as formatting the currently selected characters to italic. Generally, the KeyPress event can be used to trap keystrokes and to make void their values. Unfortunately, the KeyAscii value in the KeyPress event is 9 on pressing CTRL+i, which is the same value as a normal tab character. Therefore, we have to…

TX Text Control inserts a tab character when the key combination CTRL+i is used. This short code sample shows you how to trap these keystrokes in order to implement some other behavior, such as formatting the currently selected characters to italic.
Generally, the KeyPress event can be used to trap keystrokes and to make void their values. Unfortunately, the KeyAscii value in the KeyPress event is 9 on pressing CTRL+i, which is the same value as a normal tab character. Therefore, we have to use a global flag that returns the state of the CTRL key.
Consider the following:
Dim ctrl_key_state As Boolean
Private Sub TXTextControl1_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = 2 Then
ctrl_key_state = True
Else
ctrl_key_state = False
End If
End Sub
Private Sub TXTextControl1_KeyPress(KeyAscii As Integer)
If ctrl_key_state = True Then
If KeyAscii = 9 Then
KeyAscii = 0
If TXTextControl1.FontItalic = 0 Or TXTextControl1.FontItalic = 2 Then
TXTextControl1.FontItalic = 1
Else
TXTextControl1.FontItalic = 0
End If
End If
End If
End Sub
ActiveX
TX Text Control ActiveX is a royalty-free, fully programmable rich edit control that offers developers a broad range of word processing features in a reusable component. It provides comprehensive text formatting, powerful mail merge features and all word processing key concepts such as table support, images, headers and footers and page sections.
Related Posts
How to Get the Last Line in TX Text Control ActiveX
I have been asked today how to check, if the cursor is in the last line. Here is the resulting code snippet, which includes the extra check for the last text position in the document: Private…
Modifying Styles in TX Text Control ActiveX
TX Text Control .NET for Windows Forms offers extensive classes to modify document styles. The FormattingStyle class is the base class for the two different supported style classes: InlineStyle…
Open Documents with an Offset
TX Text Control ActiveX offers an Offset parameter to export a document with a specific file offset position. This offset can be used to save a custom file header that could contain additional…
'Change Case' in TX Text Control ActiveX
A desirable feature of a word processing application is to change the case of a word, sentence or entire document. This sample application shows you how to implement the different cases known from…
Indents and Numbered Lists
If you use the TX Text Control ActiveX button bar to insert a numbered list, you will get a different result than when you insert a numbered list simply using the ListType property. Why is this?…