How set a culture for entire winform application

Multi tool use


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?
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.
yes you did it right, No it's not necessary.
– Bijan
12 hours ago