是否可以将Windows语言栏设置为英语或从c#应用程序返回默认值

时间:2010-01-14 15:57:27

标签: c#

我有一个C#应用程序,需要将Windows语言栏设置为英语或至少恢复为默认设置。我知道我可以设置我自己的应用程序的InputLanguage但我需要设置Windows的输入语言。这可以使用语言栏手动完成,但我需要一种以编程方式执行此操作的方法。有没有办法做到这一点?

3 个答案:

答案 0 :(得分:0)

我没有这样做,因为Windows XP处于童年时代,所以你可能想要检查语言支持是否仍然基于相同的原则。它都是Win32,因此需要为C#导入它们。

首先,在MSDN上阅读有关键盘输入的页面: http://msdn.microsoft.com/en-us/library/ms645530%28VS.85%29.aspx

GetKeyboardLayoutList告诉您安装了什么布局 LoadKeyboardLayout加载新的输入区域设置标识符。 ActivateKeyboardLayout设置当前语言

答案 1 :(得分: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();
    }
}

答案 2 :(得分: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;
}

查看完整帖子:Language Bar change language in c# .NET