Click here to Skip to main content
15,868,016 members
Articles / Programming Languages / C#
Article

Set the Culture and UI Culture for Windows Forms Globalization

Rate me:
Please Sign up or sign in to vote.
1.17/5 (20 votes)
28 Mar 20072 min read 69.7K   1.1K   10   11
In some instances, you may want to have most of your application change according to the operating system's or user's culture settings, You can have culture-specific classes format the information with the invariant culture,

Screenshot - Sin_título-1.gif



Spanish


Establecer los valores Culture y UI Culture para la globalización de formularios Windows Forms

IntroducciónEn este artículo pretendo mostrar como independizar la aplicación de windows form de la configuración regional de windows.Muchas veces disponemos de diferentes aplicaciones en una misma PC y dependemos de la configuración regional del sistema. El tratamiento de los dígitos decimales en aplicaciones Windows, queda sometido siempre al uso del carácter que separa o diferencia la parte entera de la parte decimal de una cantidad numérica.A través del Panel de Control, podemos acceder a la aplicación denominada Configuración Regional y de Idioma. El problema surge cuando nuestra aplicación utiliza un símbolo decimal diferente al asignado dentro de <personname w:st="on" productid="la Configuración Regional">

la Configuración Regional y más aún, cuando tenemos dos aplicaciones Windows diferentes dentro del mismo sistema de producción que hacen uso de dos caracteres distintos de distinción entre la parte entera y la parte decimal. Si desea reemplazar la configuración del usuario o del sistema operativo, hay que establecer las propiedades CurrentCulture y CurrentUICulture. En general, se deseará especificar una referencia cultural en la que todas las partes que componen la interfaz del usuario sean apropiadas para esa referencia cultural. Por tanto, se deberá establecerla antes de que se llame al método InitializeComponent.

Para eso debemos establecer la cultura a utilizar en el archivo Program.cs



English

Set the Culture and UI Culture for Windows Forms Globalization

Introduction In this article I try to show like freeing the application from Windows form of the regional configuration of Windows. The two culture values of a Visual basic or Visual C# application determine what resources are loaded for an application and how information like currency, numbers and dates is formatted. The resources loaded are determined by the UI culture setting, and the formating options are determined by the culture setting.

The first place an application will search for culture valuesis the CurrentCulture and CurrentUICulture properties. You can set these values in code as shown in the following procedure.The CurrentCulture property's default value is the operating system's User Locale, which is set in the Regional Options control panel.
The CurrentUICulture property's default value is the operating system's user interface (UI) language, which is the language of your
operating system UI. On Windows 2000 and Windows XP MultiLanguage Edition, the CurrentUICulture defaults to the current user UI language settings.

If you want to override the settings of the user or operating system, set the CurrentCulture and CurrentUICulture properties. Usually, you want to specify a culture so that every part of the application's UI is appropriate to that culture. So you must set the culture before the InitializeComponent method is called.

Code of Program.cs

//Program.cs
 
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Windows.Forms; //agregar este espacio de nombre
using System.Threading;//agregar este espacio de nombre
 
 
 
namespace MiApp
{
 
static class Program    {
 
 
        [STAThread]
 
        public static void <place w:st="on" />Main()</place /><place w:st="on" />
 
        {
 
            Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
 
            // Seteamos la cultura a Español Argentina
            Thread.CurrentThread.CurrentCulture = new CultureInfo("es-AR");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-AR");//
 
            Application.Run(new form1());
 
 
        }
 
    
    }
 
}
 
 
 
 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Argentina Argentina
Juan Manuel De Castro es un respetado desarrollador de aplicaciones Windows y Web desde 1999. Nacido en Capitán Bermúdez, Argentina. Actualmente dirige el área tecnológica de Pronexo.com - www.pronexo.com y lidera otros proyectos tecnológicos.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Pavel Vladov30-Mar-09 0:50
Pavel Vladov30-Mar-09 0:50 
Haha, so you call 2 lines of code an article ???
NewsEnglish translation available here Pin
Ravi Bhavnani29-Mar-07 2:13
professionalRavi Bhavnani29-Mar-07 2:13 
GeneralEnglish Pin
NormDroid28-Mar-07 23:14
professionalNormDroid28-Mar-07 23:14 
GeneralRe: English Pin
JM ® - DE CASTRO29-Mar-07 2:29
JM ® - DE CASTRO29-Mar-07 2:29 
AnswerRe: English Pin
JM ® - DE CASTRO29-Mar-07 2:33
JM ® - DE CASTRO29-Mar-07 2:33 
GeneralRe: English Pin
NormDroid29-Mar-07 2:34
professionalNormDroid29-Mar-07 2:34 
AnswerRe: English Pin
JM ® - DE CASTRO29-Mar-07 2:42
JM ® - DE CASTRO29-Mar-07 2:42 
Generalfor someone being on codeproject since about 3 years and 8 months... Pin
toxcct28-Mar-07 22:12
toxcct28-Mar-07 22:12 
AnswerRe: for someone being on codeproject since about 3 years and 8 months... Pin
JM ® - DE CASTRO29-Mar-07 2:34
JM ® - DE CASTRO29-Mar-07 2:34 
GeneralInglés por favor Pin
Not Active28-Mar-07 17:35
mentorNot Active28-Mar-07 17:35 
AnswerRe: Inglés por favor Pin
JM ® - DE CASTRO29-Mar-07 2:35
JM ® - DE CASTRO29-Mar-07 2:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.