0

How does one set text of two labels with two different cultural/region format options? For first label to be ar-EG : Arabic - Egypt and second one to be en-US : English - United States ?

This to be done for Number/Date/Time/Currency formats.

Ahmed Atia
  • 17,848
  • 25
  • 91
  • 133

2 Answers2

1

Use the culture explicitly in the ToString() method. For example:

  DateTime dt = DateTime.Now;
  CultureInfo arabic = CultureInfo.GetCultureInfo("ar-EG");
  label1.Text = dt.ToString(arabic.DateTimeFormat);
  CultureInfo english = CultureInfo.GetCultureInfo("en-US");
  label2.Text = dt.ToString(english.DateTimeFormat);

Use CultureInfo.NumberFormat to format numbers.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
0

I think this maybe can solve your problem:

I needed to show different money values in two differents cultural format. So i did this right after each of the code-line asingning the value:

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

// Asign your label here

CultureInfo AR = new CultureInfo("ar-EG");  
Thread.CurrentThread.CurrentCulture = AR;

//Asign label here

Just remember to add the folowing namespace to the top of your code-file:

using System.Threading;
using System.Globalization;

and to re-set the previous culture. You can even override the System culture info just by adding those lines on the program.cs

josecortesp
  • 1,526
  • 4
  • 21
  • 38
  • This doesn't work in case of Number, it always show US format? – Ahmed Atia Dec 02 '09 at 08:54
  • Actually, it should do, it works with me(using es-CR and en-US). Remember that code gets the cultural config from the OS, so if you have configured your "ar-EG" diferently as it should be, it will take that paramethers to format your currency/dates and so on... – josecortesp Dec 03 '09 at 01:37