InputLanguage.FromCulture(CultureInfo) 方法

定义

返回与指定区域性关联的输入语言。

public:
 static System::Windows::Forms::InputLanguage ^ FromCulture(System::Globalization::CultureInfo ^ culture);
public static System.Windows.Forms.InputLanguage FromCulture (System.Globalization.CultureInfo culture);
public static System.Windows.Forms.InputLanguage? FromCulture (System.Globalization.CultureInfo culture);
static member FromCulture : System.Globalization.CultureInfo -> System.Windows.Forms.InputLanguage
Public Shared Function FromCulture (culture As CultureInfo) As InputLanguage

参数

culture
CultureInfo

CultureInfo,指定要从其转换的区域性。

返回

InputLanguage,表示以前选定的输入语言。

示例

下面的代码示例将默认输入语言设置为当前输入语言。

首先, DefaultInputLanguage 调用 以获取系统默认语言。 接下来, CurrentInputLanguage 调用 以获取当前输入语言。 结果在文本框中打印。 然后,使用默认输入语言调用 CurrentInputLanguage 会将当前输入语言更改为默认值。 新的当前输入语言显示在文本框中。

此代码假定 textBox1 已实例化。

public:
   void SetNewCurrentLanguage()
   {
      // Gets the default, and current languages.
      InputLanguage^ myDefaultLanguage = InputLanguage::DefaultInputLanguage;
      InputLanguage^ myCurrentLanguage = InputLanguage::CurrentInputLanguage;
      textBox1->Text = String::Format( "{0}Current input language is: {1}\n",
         myCurrentLanguage->Culture->EnglishName, myDefaultLanguage->Culture->EnglishName );
      
      //Print the new current input language.
      InputLanguage^ myCurrentLanguage2 = InputLanguage::CurrentInputLanguage;
      textBox1->Text = String::Format( "{0}New current input language is: {1}",
         textBox1->Text, myCurrentLanguage2->Culture->EnglishName );
   }
 public void SetNewCurrentLanguage() {
    // Gets the default, and current languages.
    InputLanguage myDefaultLanguage = InputLanguage.DefaultInputLanguage;
    InputLanguage myCurrentLanguage = InputLanguage.CurrentInputLanguage;
    textBox1.Text = "Current input language is: " +
        myCurrentLanguage.Culture.EnglishName + '\n';
    textBox1.Text += "Default input language is: " +
        myDefaultLanguage.Culture.EnglishName + '\n';
 
    //Print the new current input language.
    InputLanguage myCurrentLanguage2 = InputLanguage.CurrentInputLanguage;
    textBox1.Text += "New current input language is: " +
        myCurrentLanguage2.Culture.EnglishName;
}
Public Sub SetNewCurrentLanguage()
   ' Gets the default, and current languages.
   Dim myDefaultLanguage As InputLanguage = InputLanguage.DefaultInputLanguage
   Dim myCurrentLanguage As InputLanguage = InputLanguage.CurrentInputLanguage
   textBox1.Text = "Current input language is: " & _
       myCurrentLanguage.Culture.EnglishName + ControlChars.Cr
   textBox1.Text &= "Default input language is: " & _
       myDefaultLanguage.Culture.EnglishName + ControlChars.Cr
       
   'Print the new current input language.
   Dim myCurrentLanguage2 As InputLanguage = InputLanguage.CurrentInputLanguage
   textBox1.Text &= "New current input language is: " & _
       myCurrentLanguage2.Culture.EnglishName
End Sub

注解

方法 FromCulture 从所有已安装的键盘布局列表中返回匹配 culture 的第一个键盘布局。 如果在单个用户语言下安装了多个键盘,则可能会返回意外值。

具体而言,此方法执行以下操作:

  1. 获取函数) (HKL GetKeyboardLayoutList 的可用输入语言标识符的完整列表。

  2. 查找对应于 的 cultureHKL(如果存在)。

  3. 返回与该 HKL 关联的已安装键盘。

  4. 如果未找到键盘,则 null返回 。

备注

FromCulture如果尚未为 culture安装其他键盘, 方法永远不会尝试加载或安装其他键盘。 使用平台 SDK 函数 LoadKeyboardLayout安装其他键盘。

适用于

另请参阅