3
Answers

Set CultureInfo for winform application.

Jay S

Jay S

11y
4.6k
1
I've googled this for ages with no set answer/solution.

I have a simple C# application which has a main form (lets call it Form1) with some sub forms which are opened by button clicks etc.

My application generally works, but seems users in some countries of the world have issues/crashes.

Nearly all of the come out with this error:

system.formatexception

I thought it was something to do with my formats etc so as a intirim fix if users changed there's language/location/formats to English(United Kingdom) it worked, I have had reported that users don't even need to change this, all they had to do was change the Non-Unicode setting in the control panel to English(United Kingdom)

As a fix I amended all my datetime formatting (As this is pretty much the only formatting I think I do) with Culture Invariant.

This has limited success, so at the top of "Form1" before the InitializeComponent() I placed:

            System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("en-GB");
            Application.CurrentCulture = cultureInfo;
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");

This actually seemed to work for almost all, my USA users were happy and had no issues.

The problem I am still having is specifically from South Korea, whether other countries are facing the same issue I don't know, but I definatly know SK are still getting the System.FormatExecption error.

So, question is, how do i force the whole (Small) program to use en-GB for all settings, and/or have I done my threading properly to make sure the thread uses the correct culture information.
Answers (3)