Is it possible to override the CurrentCulture and the CurrentUICulture for a specific control in WinForms? So that this one specific control uses a different culture?
Is it possible to override the CurrentCulture and the CurrentUICulture for a specific control
Share
You can achieve that by instantiating the CultureInfo of your choice and pass that as a parameter to formatting functions (such as ToString). Just don’t assign it to Thread.CurrentThread.CurrentCulture or Thread.CurrentThread.CurrentUICulture, since that will change the culture for the application as such.
In your code:
If your code executes external code, and you want to force this code to use your internally chosen culture, you can do that by creating a new thread, assign the culture to that thread and then have that thread execute the code. Just make sure to pay attention to the threading issues that comes with that approach.
Thread sample:
As a last point; I don’t know why you want to override the CurrentCulture, but I would suggest that you think twice before doing so. Users are used to seeing dates an numbers formatted according to their locale; changing that could be confusing, especially if it happens in just one part of the UI.