Products Technologies Demo Docs Blog Support Company

FontItalic on CTRL+i with TX Text Control ActiveX

By default, TX Text Control ActiveX inserts a tab character when the user presses CTRL+I because both share KeyAscii value 9. This VB sample tracks the CTRL key state in KeyDown, nullifies the tab in KeyPress, and toggles FontItalic to apply italic formatting on the selection.

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 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

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

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.

See ActiveX products

Related Posts

ActiveXLinesSample

How to Get the Last Line in TX Text Control ActiveX

Detecting whether the cursor sits on the last line in TX Text Control ActiveX requires checking SelStart against both the full text length and the result of GetLineFromChar against GetLineCount.…


ActiveXSample

Modifying Styles in TX Text Control ActiveX

TX Text Control .NET for Windows Forms exposes FormattingStyle as the base class for InlineStyle and ParagraphStyle. In the ActiveX edition, the Style object and Styles collection let developers…


ActiveX.NETSample

Open Documents with an Offset

TX Text Control ActiveX supports saving documents with a byte offset to embed custom file headers. In TX Text Control .NET for Windows Forms, a FileStream with its Position property set to the…


ActiveXSample

'Change Case' in TX Text Control ActiveX

This sample application implements Word-style case conversion in TX Text Control ActiveX using Visual Basic. It covers five modes: UPPER CASE, lower case, Title Case, tOgGlE cAsE, and Sentence…


ActiveXSample

Indents and Numbered Lists

The TX Text Control ActiveX button bar inserts numbered lists with different indentation than the ListType property alone. This code sample reproduces the exact button bar formatting by combining…

Share on this blog post on: