Winforms阿拉伯语输入文本框

本文关键字:文本 输入 阿拉伯语 Winforms | 更新日期: 2023-09-27 18:19:40

在我的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);   
        }

但当我在文本框中键入时,它仍然键入英文字母而不是阿拉伯语。我应该做什么

Winforms阿拉伯语输入文本框

您可以这样使用:

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