2013-06-22 146 views
1

在我的Windows應用程序窗體(c#),我有阿拉伯文和英文文本框。對於阿拉伯語文本框,我想自動將我的語言轉換爲阿拉伯語而不用按(alt + shift)。我在互聯網上找到這個解決方案,我實現了它在文本框中輸入Winforms阿拉伯文輸入文本框

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

     } 

但仍當我鍵入文本框中這類型的英文字母,而不是阿拉伯語。我應該怎麼辦

+0

嘗試'System.Threading.Thread.CurrentThread.CurrentCulture = TypeOfLanguage;' –

+0

我think.you希望得到焦點事件 – Sayse

+0

我試過System.Threading.Thread.CurrentThread.CurrentCulture,但仍然沒有成功。 – Tanveer

回答

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

如果用戶安裝了多種語言,那麼正確的方法是什麼?或者我們如何知道0是阿拉伯語或英語? – Tanveer

+0

@Tanveer此鏈接可能會有幫助http://blogs.msdn.com/b/vsarabic/archive/2007/04/29/changing-the-input-language-in-a-textbox-at-runtime.aspx –

+0

@Tanveer我已經更新了我的答案。 –