How to receive event when user changes system's culture

后端 未结 2 1202
情话喂你
情话喂你 2020-12-01 22:08

When my application run with a specified culture. Don\'t close the application, user changes system\'s culture, ex: change number decimal separator from \".\" to \",\". How

相关标签:
2条回答
  • 2020-12-01 22:30

    If you want to trach system language changes then you have SystemEvents object which contains UserPreferenceChanged event you can attach to.

    Sample:

    Microsoft.Win32.SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
    

    If you want to track input language changes (like changes in system try when you choose between languages), then you can use: System.Windows.Forms.InputLanguage.CurrentInputLanguage

    Sample:

    string inputLanguage = System.Windows.Forms.InputLanguage.CurrentInputLanguage.LayoutName;
    
    0 讨论(0)
  • 2020-12-01 22:43

    You can handle the SystemEvents.UserPreferenceChanged event:

    void SystemEvents.UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
    {
        // Regional settings have changed
        if (e.Category == UserPreferenceCategory.Locale)
        {
            ...
        }
    }
    
    0 讨论(0)
提交回复
热议问题