RadRichTextBox provides built-in support for the most commonly used Microsoft IMEs like Chinese IME, Japanese IME, Korean IME and etc. which are shipped with the Windows OS. Further, you can easily add support for the IME which is used in your application.
The caret is the UI which represents where the current document position is. It also provides ability to modify the text. It exposes several events which are corresponding to the relevant text operation.
- TextInputStart: This event is fired when a UI element initially gets text.
- TextInputUpdate: This event is fired when text continues to be composed and IME is used.
- TextInput: This event is fired when the text should be committed.
The CaretTextInputHandler class is responsible for the text insertion in RadRichTextBox. It is attached to the Caret’s TextInserted event, which has TextInsertedEventArgs as event arguments.
- Text: This property represents the text which is entered.
- ShouldPersist: This property carries the information if the composition text should be persisted.
- ShouldStartNewComposition: This property identifies if a new text composition should be started.
When you are executing your logic in the overridden Caret event handlers, it is important to execute the OnTextInserted method with the desired TextInsertedEventArgs, so the TextInserted event will be fired and the CaretTextInputHandler will process the text depending on the arguments.
If you want to add support for another input method editor, you can easily achieve it by creating a custom caret and plug it in the RadRichTextBox. Here is what is necessary to know before doing that.
The ICaretFactory interface has a CreateCaret() method which is responsible for the caret creation. It returns the caret which should handle the text input.
To achieve a different than the Microsoft IME support, you should implement your own caret which inherits RadRichTextBox’s Caret class and overrides the handlers of the above mentioned events. In these overridden methods you can execute the specific logic for the corresponding input method editor.
public class SogouCaret : Caret
protected override void OnTextInputStart(object sender, TextCompositionEventArgs e)
protected override void OnTextInputUpdate(object sender, TextCompositionEventArgs e)
protected override void OnTextInput(TextCompositionEventArgs e)
Public Class SogouCaret
Protected Overloads Sub OnTextInputStart(ByVal sender As Object, ByVal e As TextCompositionEventArgs)
Protected Overloads Sub OnTextInputUpdate(ByVal sender As Object, ByVal e As TextCompositionEventArgs)
Protected Overloads Sub OnTextInput(ByVal e As TextCompositionEventArgs)
The inherited caret should be created by a factory class, which should implement the ICaretFactory interface.
public class SogouCaretFactory : ICaretFactory
public Caret CreateCaret()
return new SogouCaret();
Public Class SogouCaretFactory
Public Function CreateCaret() As Caret Implements ICaretFactory.CreateCaret
Return New SogouCaret()
The last thing you should do, is to set the RadRichTextBox’ CaretFactory property to be your factory class.
this.radRichTextBox.CaretFactory = new SogouCaretFactory();
Me.radRichTextBox.CaretFactory = new SogouCaretFactory()
You can download a runnable project of the previous example from our online SDK repository here.