views:

3504

answers:

5

how to set internationalization to a DateTimepicker or Calendar WinForm control in .Net when the desire culture is different to the one installed in the PC?

A: 

For DateTimePicker

dtp.Format = DateTimePickerFormat.Custom;
dtp.CustomFormat = "yyyy-MM-dd"; // or the format you prefer
Hapkido
Setting the format is not the only thing controlled by the culture. It controls a lot of other things, such as whether the first day of the week is Sunday or Monday.
Kibbee
Format is used only to show current date, but if you want to choose it, datetimepicker control will show full date, based on the regional settings.
Nenad
+3  A: 

It doesn't seem to be possible to change the culture. See this KB article.

Jonas Lincoln
A: 
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("fr");
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
Bigballs
That will not change the regional settings of the Windows, only the current UI culture and current culture of the current thread (as the properties' names suggest). But DateTimePicker control looks only for the regional setting of the Windows, so it doesn't matter.
Nenad
A: 

I think there is detour.

  1. set event handler "ValueChanged"
  2. code

    dateTimePicker.Format = DateTimePickerFormat.Custom;
    string[] formats = dateTimePicker.Value.GetDateTimeFormats(Application.CurrentCulture);
    dateTimePicker.CustomFormat = formats[0];
    
heejong
A: 

Based on previous solution, I think the better is:

dateTimePicker.Format = DateTimePickerFormat.Custom;
dateTimePicker.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern;
KaDim
will give it a try thanks
Oscar Cabrero