Exemple #1
0
        public static void SetLocale(string locale = null)
        {
            // Only want to reset locale temporarily so save current value
            string currentkeyboardlocale = KeyboardHelper.GetCurrentKeyboardLocale();

            if (String.IsNullOrEmpty(locale))
            {
                // At startup we need to load the current locale.
                locale = currentkeyboardlocale;
            }

            if ((locale != currentLocale))
            {
                if (customKeyboardLayouts != null && customKeyboardLayouts.ContainsKey(locale))
                {
                    KeyboardLayout = (KeyboardLayoutType)customKeyboardLayouts[locale];
                }
                else
                {
                    // Ask the keydata interface what kind of layout this locale has - US, Euro etc.
                    KeyboardLayout = new KeyDataXml().GetKeyboardLayoutType(locale);
                }

                // Load the keyboard layout for the minimum possible time and keep the results:
                // This can error with some cultures, problems with framework, unhandled thread exception occurs.
                try
                {
                    // if (_currentCultureInfo != null)
                    // Console.WriteLine("Setting culture to: LCID: {0}", _currentCultureInfo.LCID);

                    int culture = KeyboardHelper.SetLocale(locale);
                    CurrentCultureInfo = new CultureInfo(culture);

                    _currentLayout = new LocalizedKeySet();
                    currentLocale  = locale;
                }

                catch (Exception ex)
                {
                    Console.WriteLine("Set Locale Exception: {0}", ex);
                }

                finally
                {
                    // Set it back (if different)
                    if (currentLocale != currentkeyboardlocale)
                    {
                        KeyboardHelper.SetLocale(currentkeyboardlocale);
                    }
                }
            }
        }
Exemple #2
0
        public static void SetLocale(string locale = null)
        {
            // Only want to reset locale temporarily so save current value
            string currentkeyboardlocale = KeyboardHelper.GetCurrentKeyboardLocale();

            if (String.IsNullOrEmpty(locale))
            {
                // At startup we need to load the current locale.
                locale = currentkeyboardlocale;
            }

            if ((locale != currentLocale))
            {
                if (customKeyboardLayouts != null && customKeyboardLayouts.ContainsKey(locale))
                    KeyboardLayout = (KeyboardLayoutType)customKeyboardLayouts[locale];
                else
                {
                    // Ask the keydata interface what kind of layout this locale has - US, Euro etc.
                    KeyboardLayout = new KeyDataXml().GetKeyboardLayoutType(locale);
                }

                // Load the keyboard layout for the minimum possible time and keep the results:
                // This can error with some cultures, problems with framework, unhandled thread exception occurs.
                try
                {
                    // if (_currentCultureInfo != null)
                    // Console.WriteLine("Setting culture to: LCID: {0}", _currentCultureInfo.LCID);

                    int culture = KeyboardHelper.SetLocale(locale);
                    CurrentCultureInfo = new CultureInfo(culture);

                    _currentLayout = new LocalizedKeySet();
                    currentLocale = locale;
                }

                catch (Exception ex)
                {
                    Console.WriteLine("Set Locale Exception: {0}", ex);
                }

                finally
                {
                    // Set it back (if different)
                    if (currentLocale != currentkeyboardlocale)
                        KeyboardHelper.SetLocale(currentkeyboardlocale);
                }
            }
        }