Winforms Arabic Input text box

2020-04-20 08:09发布

on my windows application form (c#) , i have arabic and english text boxes. for Arabic text boxes i want to automatically shift my language to arabic without presshing (alt + shift). I found this solution on internet and i implemented it on TextBox Enter

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

        }

But still when i type in text box it types english letters instead of arabic. what should i do

标签: c# .net
1条回答
够拽才男人
2楼-- · 2020-04-20 08:58

you can use this way :

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

        }

0: Language 1 that installed on your system
1: Language 2 that installed on your system ,...

Updated :

 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;
        }
查看更多
登录 后发表回答