我有一個C#應用程序,需要將Windows語言欄設置爲英文或至少恢復爲默認設置。我知道我可以設置自己的應用程序的InputLanguage,但我需要爲Windows設置輸入語言。這可以使用語言欄手動完成,但我需要一種以編程方式執行的方法。有沒有辦法做到這一點?是否可以將Windows語言欄設置爲英文或從c#應用程序恢復爲默認設置
3
A
回答
0
我落得這樣做:
Process[] apps=Process.GetProcesses();
foreach (Process p in apps)
{
if (p.MainWindowHandle.ToInt32()>0)
{
NativeWin32.SetForegroundWindow(p.MainWindowHandle.ToInt32());
//send control shift 2 to switch the language bar back to english.
System.Windows.Forms.SendKeys.SendWait("^+(2)");
p.Dispose();
}
}
0
自從Windows XP在童年時代以來,我還沒有這樣做過,所以您可能想要檢查語言支持是否仍然基於相同的原則。它都是Win32,因此需要爲C#導入它們。
首先,在MSDN上關於鍵盤輸入的頁面閱讀: http://msdn.microsoft.com/en-us/library/ms645530%28VS.85%29.aspx
GetKeyboardLayoutList告訴你什麼佈局安裝 LoadKeyboardLayout加載新的輸入法區域設置IDENTIFER。 ActivateKeyboardLayout設置當前語言
0
一個更好的這種做法是這樣的:
//change input language to English
InputLanguage currentLang = InputLanguage.CurrentInputLanguage;
InputLanguage newLang = InputLanguage.FromCulture(System.Globalization.CultureInfo.GetCultureInfo("en-US"));
if (newLang == null)
{
MessageBox.Show("The Upload Project function requires the En-US keyboard installed.", "Missing keyboard", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
else
{
InputLanguage.CurrentInputLanguage = newLang;
}