views:

114

answers:

1

I am working on a C# app that tries to respect the time format of the system it is running on. If the Windows control panel is changed to 24 hour format, that is the format the app will display time in. Anyway, it does this successfully, except it will only work if the time format is changed before the app is run. If you change the Windows time format while the app is running, it will not use the updated format.

Is there any kind of Windows event or other way to retrieve the latest time format? We currently use the DateTimeFormatInfo LongTimePattern because it changes based on whether we are in 12 or 24 hour time.

+7  A: 

There is a class SystemEvents in the Microsoft.Win32 namespace which has a set of static events you can subscribe to. You'll want to subscribe to the UserPreferenceChanged event:

SystemEvents.UserPreferenceChanged += new UserPreferenceChanged;

/* Other stuff... */

private static void UserPreferenceChanged(object s, UserPreferenceChangedEventArgs e)
{
    if (e.Category == UserPreferenceCategory.Locale)
    {
        /* They changed regional settings, so do your work here */
    }
}
Sean Bright