Winforms阿拉伯语输入文本框

时间:2013-06-22 07:16:34

标签: c# .net

在我的Windows申请表(c#)上,我有阿拉伯文和英文文本框。对于阿拉伯语文本框我想自动将我的语言转换为阿拉伯语而不用压力(alt + shift)。我在互联网上找到了这个解决方案,我在TextBox Enter

上实现了它
 private void TextArabs_Enter(object sender, EventArgs e)
        {              
            System.Globalization.CultureInfo TypeOfLanguage = new System.Globalization.CultureInfo("ar");
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(TypeOfLanguage);   

        }

但是当我输入文本框时,它会输入英文字母而不是阿拉伯语。我该怎么办

1 个答案:

答案 0 :(得分:3)

你可以这样使用:

private void TextArabs_Enter(object sender, EventArgs e)
        {              
            InputLanguage.CurrentInputLanguage =
                InputLanguage.InstalledInputLanguages[1];   

        }

0:系统上安装的语言1 1:系统上安装的语言2,......

更新:

 InputLanguage arabic;
        InputLanguage english;
        private void Form1_Load(object sender, EventArgs e)
        {
            arabic = InputLanguage.CurrentInputLanguage;
            english = InputLanguage.CurrentInputLanguage;
            int count = InputLanguage.InstalledInputLanguages.Count;
            for (int i = 0; i <= count - 1; i++)
            {
                if (InputLanguage.InstalledInputLanguages[i].LayoutName.Contains("Arabic"))
                {
                    arabic = InputLanguage.InstalledInputLanguages[i];
                }
                if (InputLanguage.InstalledInputLanguages[i].LayoutName.Contains("English"))
                {
                    english = InputLanguage.InstalledInputLanguages[i];
                }
            }
        }
        private void txtArabic_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = arabic;
        }

        private void txtEnglish_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = english;
        }