Title: List the defined locales in C#
This example is fairly straightforward. When the form loads, the following event handler lists the defined locales.
private void Form1_Load(object sender, EventArgs e)
{
// Make the ListBox use tabs.
lstLocales.UseTabStops = true;
lstLocales.UseCustomTabOffsets = true;
// Define the tabs.
ListBox.IntegerCollection offsets =
lstLocales.CustomTabOffsets;
offsets.Add(100);
// Add the locale information.
foreach (CultureInfo info in
CultureInfo.GetCultures(CultureTypes.AllCultures))
{
lstLocales.Items.Add(
info.EnglishName + '\t' +
info.NativeName);
}
// Display the number of locales.
lblNumLocales.Text = lstLocales.Items.Count.ToString() +
" locales";
}
The code prepares the ListBox to use tab stops. It then loops through the CultureInfo objects returned by CultureInfo.GetCultures(CultureTypes.AllCultures). For each CultureInfo object, the program adds the object's English and native names separated by a tab to the ListBox. It finishes by displaying the number of locales.
Download the example to experiment with it and to see additional details.
|