我有一个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;
}