Edit

Share via


InputLanguage.FromCulture(CultureInfo) Method

Definition

Returns the input language associated with the specified culture.

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

Parameters

culture
CultureInfo

The CultureInfo that specifies the culture to convert from.

Returns

An InputLanguage that represents the previously selected input language.

Examples

The following code example sets the default input language as the current input language.

First, DefaultInputLanguage is called to get the system default language. Next, CurrentInputLanguage is called to get the current input language. The results are printed in a text box. Then, calling CurrentInputLanguage with the default input language changes the current input language to the default. The new current input language is displayed in a text box.

This code assumes that textBox1 has been instantiated.

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

Remarks

The FromCulture method returns the first keyboard layout with matching culture from the list of all installed keyboard layouts. It might return an unexpected value if multiple keyboards are installed under a single user language.

Specifically, this method performs the following operations:

  1. Gets the full list of available input language identifiers (HKLs) from the GetKeyboardLayoutList function.

  2. Finds the HKL that corresponds to the culture, if one is present.

  3. Returns the installed keyboard associated with that HKL.

  4. If no keyboard is found, returns null.

Note

The FromCulture method never tries to load or install an additional keyboard if one has not already been installed for culture. Use the Platform SDK function, LoadKeyboardLayout, to install an additional keyboard.

Applies to

See also