0

As explained here I have built a sample console application in which I change the culture in the Main function. It works well.

Now, building another sample winform application, I wonder where would be the best place to put this

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture ("en-US");
Thread.CurrentThread.CurrentUICulture=new CultureInfo("en-US");

If I put this in the constructor of a Form1, will this apply to all operations in this class?

What if this Form1 opens another form Form2 and an exception occurs there?

What if Form1 uses another class Class1?

I am willing to experiment in this, but if someone has an answer based on previous knowledge, I appreciate to hear it.

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150
  • You're setting `CultureInfo` to the thread so every object bound to that thread ( created in it's context ) will use the same `CultureInfo` – mrogal.ski Feb 07 '18 at 08:21

1 Answers1

1

For a winforms application put things that deal with the context of the entire application in program.cs and be done with it.

  • If I put this in the constructor of a Form1, will this apply to all operations in this class?

  • What if this Form1 opens another form Form2 and an exception occurs there?

  • What if Form1 uses another class Class1?

All your other concerns are irrelevant, and are sereverly overthinking the problem.

Note : The best way to learn programming windows or any other language is to read as much as you can. Microsoft have everything documented always go straight to the source.

Some additional reading for you

Thread.CurrentUICulture Property

Thread.CurrentCulture Property

Initialization code in a WinForms App - Program.cs or MainForm?

TheGeneral
  • 79,002
  • 9
  • 103
  • 141