i am working with a winform application , and in the richbox_textchange i would like to detect whether the entered text is English or not because if it is english i`ll perform LeftToRight typing else RightToLeft typing .
I used that code :
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
if (CultureInfo.CurrentCulture.TextInfo.IsRightToLeft)
{
label1.Text = "RTL";
}
else
{
label1.Text = "LTR";
}
}
but i always get : LTR only , label1 never change text to RTL even if i typed arabic !!!
EDIT : ANSWERED !!
Firstly Thanks to everybody for helping me here and especially Oded , here is the solution i could figure out
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
if (InputLanguage.CurrentInputLanguage.Culture.TextInfo.IsRightToLeft)
{
label1.Text = "RTL";
}
else
{
label1.Text = "LTR";
}
}
You need to add the correct namespace to the top of your class:
using System.Globalization;
At this point the CultureInfo
and TextInfo
classes will be available directly.
Update:
It appears that you are trying to find out the current input language. Take a look at the InputLanguage
class and its methods. It is in the System.Windows.Forms
namespace.
InputLanguage.CurrentInputLanguage.Culture.TextInfo.IsRightToLeft