How set a culture for entire winform application

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How set a culture for entire winform application



I want to set a culture for entire winform application.
How can i do that?
I changed my Program.cs file like this :


Program.cs


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Divar
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
var culture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new RadForm1());
}
}
}



Did i do it right?



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");



Is it necessary to add those three lines before the InitializeComponent() in every form?





yes you did it right, No it's not necessary.
– Bijan
12 hours ago







Should i add this line > Application.CurrentCulture = cultureInfo; > to Main() method too?
– SilverLight
11 hours ago







Can u explain about those six lines about culture!
– SilverLight
11 hours ago







nothing to explain really. the names of the properties are self-explanatory. and to be sure you can set all four of them in Main
– Bijan
11 hours ago


Main





stackoverflow.com/a/32990088/3110834
– Reza Aghaei
6 hours ago




1 Answer
1



Set these two in Main to the desired culture:
CultureInfo.DefaultThreadCurrentCulture
CultureInfo.DefaultThreadCurrentUICulture


Main


CultureInfo.DefaultThreadCurrentCulture


CultureInfo.DefaultThreadCurrentUICulture



Additionally, you can change Application.CurrentCulture whenever you want to change the culture on the current thread of the application.


Application.CurrentCulture


[STAThread]
static void Main()
{
var culture = new CultureInfo("en-US");

//Culture for any thread
CultureInfo.DefaultThreadCurrentCulture = culture;

//Culture for UI in any thread
CultureInfo.DefaultThreadCurrentUICulture = culture;

//Culture for current thread (STA)
//no need for: Application.CurrentCulture = culture;

//Thread.CurrentThread.CurrentCulture == Application.CurrentCulture
//no need for: Thread.CurrentThread.CurrentCulture = culture;

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new RadForm1());
}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

5CZYXzMCUw2Epx C62v H4GLbLEE75CLiNOV2mGj5BnIDI3ynF90U
4Fh,Zi dWZOvv s GA5 z47HgHtVZgO1PqDNxE IcjnGEgGD,JgNEHjV9u0U1P4yCuH1Tgw8u,P1qF,uwSK5 jbB,o ktA X hp8fovBqjFzh t1M

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results