Reputation:
I have a vb.net form that containing 2 richtextbox. The first richtextbox in English and the second in Arabic. How can I change the cursor direction so that its direction turns to the right when entering the Arab richtextbox and to the left when entering the English richtextbox??
Upvotes: 2
Views: 797
Reputation: 4660
Perhaps you mean changing the input language on enter a RichTextBox
control? If that's what you are after, then you need to handle the Enter
event of each RTB
to switch the language through the InputLanguage
class. The class has static properties to get the installed input languages, their cultures, the default and the current input languages.
Add Enter
event handler for each RTB
and handle them as follows:
The English Language RTB
Private Sub enRTB_Enter(sender As Object, e As EventArgs) Handles enRTB.Enter
Dim lang = InputLanguage.InstalledInputLanguages.
Cast(Of InputLanguage).
FirstOrDefault(Function(x) x.Culture.TwoLetterISOLanguageName = "en")
If lang IsNot Nothing Then InputLanguage.CurrentInputLanguage = lang
End Sub
The Arabic Language RTB
Private Sub arRTB_Enter(sender As Object, e As EventArgs) Handles arRTB.Enter
Dim lang = InputLanguage.InstalledInputLanguages.
Cast(Of InputLanguage).
FirstOrDefault(Function(x) x.Culture.TwoLetterISOLanguageName = "ar")
If lang IsNot Nothing Then InputLanguage.CurrentInputLanguage = lang
End Sub
Upvotes: 1
Reputation: 16423
All controls have a property named RightToLeft
which is used to dictate the direction of text entry.
Here it is as described in the docs:
Gets or sets a value indicating whether control's elements are aligned to support locales using right-to-left fonts.
In the case of your RichTextBox
es, either set the property in the Properties window in the Form editor, or programatically like this:
EnglishRichTextBox.RightToLeft = RightToLeft.No
ArabicRichTextBox.RightToLeft = RightToLeft.Yes
If the RichTextBox
es are dedicated for English or Arabic input, you should set them at design time. There is a side effect of changing the value at runtime (in code), which is detailed in the docs:
If the value of the
RightToLeft
property is changed at run time, only raw text without formatting is preserved.
Upvotes: 2