I got DateTimePicker control.
I used the following code to set the format of the control:
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "HH:mm";
it worked with one problem. My computer culture language is RTL language (hebrew), so I see the format of the time in the control like that “mm:HH” althought I wrote “HH:mm”. It caused by the RTL culture, So I tried two ways to solve it but none of them worked / worked completely.
I tried:
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
and it didnt work at all.
I also tried to detect wheter its RTL language or not by using this code:
CultureInfo.TextInfo.IsRightToLeft
and then to reverse the format string from “HH:mm” to “mm:HH” (if its rtl language) but then I discovered another problem – in XP if its RTL language it will write the right format.. so yeah I can detect if its XP or not but I think this is too much code for simple need…
Is there easier solution?
Thanks!.
There was DTP breakage for RTL languages in Windows 7 and Server 2008 R2. The KB article is here, the forum thread that got that ball rolling is here. Not exactly a slamdunk for your case but compelling nonetheless. Try the hotfix it links to.