【问题标题】:Is it possible to set the Windows language bar to english or back to the default from a c# application是否可以将 Windows 语言栏设置为英语或从 c# 应用程序恢复为默认值
【发布时间】:2016-05-19 16:05:24
【问题描述】:

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

【问题讨论】:

    标签: c#


    【解决方案1】:

    我最终这样做了:

    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】:

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

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

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

      【讨论】:

        【解决方案3】:

        一个更好的方法是这样的:

        //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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-08-11
          • 2022-06-23
          • 2023-02-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多